History

mm: page_cache_add_speculative(): refactor out some code duplication

From: John Hubbard <jhubbard@nvidia.com> This combines the common elements of these routines: page_cache_get_speculative() page_cache_add_speculative() This was anticipated by the original author, as shown by the comment in commit ce0ad7f095258 ("powerpc/mm: Lockless get_user_pages_fast() for 64-bit (v3)"): "Same as above, but add instead of inc (could just be merged)" There is no intention to introduce any behavioral change, but there is a small risk of that, due to slightly differing ways of expressing the TINY_RCU and related configurations. This also removes the VM_BUG_ON(in_interrupt()) that was in page_cache_add_speculative(), but not in page_cache_get_speculative(). This provides slightly less detection of such bugs, but it given that it was only there on the "add" path anyway, we can likely do without it just fine. And it removes the VM_BUG_ON_PAGE(PageCompound(page) && page != compound_head(page), page); that page_cache_add_speculative() had.

john.hubbard@gmail.com committed 7 years ago

Commit 494eec71 parent f9004821 file · +9 −22Browse files

Showing the changes to include/linux (1 of 1 file). Show all

Unified · Split

include/linux/pagemap.h+9−22
@@ -164,7 +164,7 @@ void release_pages(struct page **pages, int nr); · 163 unmodified lines
164164 * will find the page or it will not. Likewise, the old find_get_page could run
165165 * either before the insertion or afterwards, depending on timing.
166166 */
167−static inline int page_cache_get_speculative(struct page *page)
167+static inline int __page_cache_add_speculative(struct page *page, int count)
168168 {
169169 #ifdef CONFIG_TINY_RCU
170170 # ifdef CONFIG_PREEMPT_COUNT
@@ -180,10 +180,10 @@ static inline int page_cache_get_speculative(struct page *page) · 9 unmodified lines
180180 * SMP requires.
181181 */
182182 VM_BUG_ON_PAGE(page_count(page) == 0, page);
183− page_ref_inc(page);
183+ page_ref_add(page, count);
184184
185185 #else
186− if (unlikely(!get_page_unless_zero(page))) {
186+ if (unlikely(!page_ref_add_unless(page, count, 0))) {
187187 /*
188188 * Either the page has been freed, or will be freed.
189189 * In either case, retry here and the caller should
@@ -197,27 +197,14 @@ static inline int page_cache_get_speculative(struct page *page) · 7 unmodified lines
197197 return 1;
198198 }
199199
200−/*
201− * Same as above, but add instead of inc (could just be merged)
202− */
203−static inline int page_cache_add_speculative(struct page *page, int count)
200+static inline int page_cache_get_speculative(struct page *page)
204201 {
205− VM_BUG_ON(in_interrupt());
206−
207−#if !defined(CONFIG_SMP) && defined(CONFIG_TREE_RCU)
208−# ifdef CONFIG_PREEMPT_COUNT
209− VM_BUG_ON(!in_atomic() && !irqs_disabled());
210−# endif
211− VM_BUG_ON_PAGE(page_count(page) == 0, page);
212− page_ref_add(page, count);
213−
214−#else
215− if (unlikely(!page_ref_add_unless(page, count, 0)))
216− return 0;
217−#endif
218− VM_BUG_ON_PAGE(PageCompound(page) && page != compound_head(page), page);
202+ return __page_cache_add_speculative(page, 1);
203+}
219204
220− return 1;
205+static inline int page_cache_add_speculative(struct page *page, int count)
206+{
207+ return __page_cache_add_speculative(page, count);
221208 }
222209
223210 #ifdef CONFIG_NUMA

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t