Skip to contentSkip to conversation

kill add_to_page_cache_locked()

PATCH In review Kent Overstreet 3 participants 6 messages Oct 21, 2020 – Nov 11, 2020

Subsystems (5)
lore
Share & tools
lore
#0 lore raw

v2 cover kill add_to_page_cache_locked()

since v1
- kill a faulty assertion found by kernel test robot
- drop an unneeded line break

Andrew, can this go through your tree?

Kent Overstreet (2):
cifs: convert to add_to_page_cache()
fs: kill add_to_page_cache_locked()

 fs/cifs/file.c          | 20 +++----------
 include/linux/pagemap.h | 20 ++-----------
 mm/filemap.c            | 64 ++++++++++++++++++++---------------------
 3 files changed, 37 insertions(+), 67 deletions(-)
Signature · 1 line
2.28.0
#1 lore raw

PATCH v2 1/2 cifs: convert to add_to_page_cache()

This is just open coding add_to_page_cache(), and the next patch will delete add_to_page_cache_locked().

---
 fs/cifs/file.c | 20 ++++----------------
 1 file changed, 4 insertions(+), 16 deletions(-)
fs/cifs/file.c +4 -16
index be46fab4c9..b3ee790532 100644
@@ -4296,20 +4296,11 @@ readpages_get_pages(struct address_space *mapping, struct list_head *page_list,
 
 	page = lru_to_page(page_list);
 
-	/*
-	 * Lock the page and put it in the cache. Since no one else
-	 * should have access to this page, we're safe to simply set
-	 * PG_locked without checking it first.
-	 */
-	__SetPageLocked(page);
-	rc = add_to_page_cache_locked(page, mapping,
-				      page->index, gfp);
+	rc = add_to_page_cache(page, mapping, page->index, gfp);
 
 	/* give up if we can't stick it in the cache */
-	if (rc) {
-		__ClearPageLocked(page);
+	if (rc)
 		return rc;
-	}
 
 	/* move first page to the tmplist */
 	*offset = (loff_t)page->index << PAGE_SHIFT;
@@ -4328,12 +4319,9 @@ readpages_get_pages(struct address_space *mapping, struct list_head *page_list,
 		if (*bytes + PAGE_SIZE > rsize)
 			break;
 
-		__SetPageLocked(page);
-		rc = add_to_page_cache_locked(page, mapping, page->index, gfp);
-		if (rc) {
-			__ClearPageLocked(page);
+		rc = add_to_page_cache(page, mapping, page->index, gfp);
+		if (rc)
 			break;
-		}
 		list_move_tail(&page->lru, tmplist);
 		(*bytes) += PAGE_SIZE;
 		expected_index++;
Signature · 1 line
2.28.0
#2 lore raw

Re: [PATCH v2 1/2] cifs: convert to add_to_page_cache()

you can add my reviewed-by if you would like

Quoted 54 lines · Kent Overstreet

This is just open coding add_to_page_cache(), and the next patch will delete add_to_page_cache_locked().

---
 fs/cifs/file.c | 20 ++++----------------
 1 file changed, 4 insertions(+), 16 deletions(-)
fs/cifs/file.c +4 -17
index be46fab4c9..b3ee790532 100644
@@ -4296,20 +4296,11 @@ readpages_get_pages(struct address_space *mapping, struct list_head *page_list,
 
        page = lru_to_page(page_list);
 
-       /*
-        * Lock the page and put it in the cache. Since no one else
-        * should have access to this page, we're safe to simply set
-        * PG_locked without checking it first.
-        */
-       __SetPageLocked(page);
-       rc = add_to_page_cache_locked(page, mapping,
-                                     page->index, gfp);
+       rc = add_to_page_cache(page, mapping, page->index, gfp);
 
        /* give up if we can't stick it in the cache */
-       if (rc) {
-               __ClearPageLocked(page);
+       if (rc)
                return rc;
-       }
 
        /* move first page to the tmplist */
        *offset = (loff_t)page->index << PAGE_SHIFT;
@@ -4328,12 +4319,9 @@ readpages_get_pages(struct address_space *mapping, struct list_head *page_list,
                if (*bytes + PAGE_SIZE > rsize)
                        break;
 
-               __SetPageLocked(page);
-               rc = add_to_page_cache_locked(page, mapping, page->index, gfp);
-               if (rc) {
-                       __ClearPageLocked(page);
+               rc = add_to_page_cache(page, mapping, page->index, gfp);
+               if (rc)
                        break;
-               }
                list_move_tail(&page->lru, tmplist);
                (*bytes) += PAGE_SIZE;
                expected_index++;
--

2.28.0

Signature · 3 lines
Thanks,

Steve
#4 lore raw

PATCH v2 2/2 fs: kill add_to_page_cache_locked()

In reply to Kent Overstreet

No longer has any users, so remove it.

---
 include/linux/pagemap.h | 20 ++-----------
 mm/filemap.c            | 64 ++++++++++++++++++++---------------------
 2 files changed, 33 insertions(+), 51 deletions(-)
include/linux/pagemap.h +2 -18
index 434c9c34ae..aceaebfaab 100644
@@ -689,8 +689,8 @@ static inline int fault_in_pages_readable(const char __user *uaddr, int size)
 	return 0;
 }
 
-int add_to_page_cache_locked(struct page *page, struct address_space *mapping,
-				pgoff_t index, gfp_t gfp_mask);
+int add_to_page_cache(struct page *page, struct address_space *mapping,
+		      pgoff_t index, gfp_t gfp_mask);
 int add_to_page_cache_lru(struct page *page, struct address_space *mapping,
 				pgoff_t index, gfp_t gfp_mask);
 extern void delete_from_page_cache(struct page *page);
@@ -710,22 +710,6 @@ void page_cache_readahead_unbounded(struct address_space *, struct file *,
 		pgoff_t index, unsigned long nr_to_read,
 		unsigned long lookahead_count);
 
-/*
- * Like add_to_page_cache_locked, but used to add newly allocated pages:
- * the page is new, so we can just run __SetPageLocked() against it.
- */
-static inline int add_to_page_cache(struct page *page,
-		struct address_space *mapping, pgoff_t offset, gfp_t gfp_mask)
-{
-	int error;
-
-	__SetPageLocked(page);
-	error = add_to_page_cache_locked(page, mapping, offset, gfp_mask);
-	if (unlikely(error))
-		__ClearPageLocked(page);
-	return error;
-}
-
 /**
  * struct readahead_control - Describes a readahead request.
  *
mm/filemap.c +31 -33

106 lines not on this page · raw message

Signature · 1 line
2.28.0
maintainer
#5 lore raw

Re: [PATCH v2 2/2] fs: kill add_to_page_cache_locked()

Quoted 3 lines · Kent Overstreet

}

mm/filemap.c +1 -1
-ALLOW_ERROR_INJECTION(__add_to_page_cache_locked, ERRNO);
+ALLOW_ERROR_INJECTION(__add_to_page_cache, ERRNO);

[..]

mm/filemap.c static int __add_to_page_cache_locked(struct page *page, · line 912

Quoted 10 lines
mm/filemap.c +5 -3
+int add_to_page_cache(struct page *page, struct address_space *mapping,
+		      pgoff_t offset, gfp_t gfp_mask)
 {
-	return __add_to_page_cache_locked(page, mapping, offset,
-					  gfp_mask, NULL);
+	return __add_to_page_cache(page, mapping, offset, gfp_mask, NULL);
 }
-EXPORT_SYMBOL(add_to_page_cache_locked);
+EXPORT_SYMBOL(add_to_page_cache);
+ALLOW_ERROR_INJECTION(add_to_page_cache, ERRNO);

I don't think you need this second one since __add_to_page_cache can be used for the same purpose.