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
164 * will find the page or it will not. Likewise, the old find_get_page could run164 * will find the page or it will not. Likewise, the old find_get_page could run
165 * either before the insertion or afterwards, depending on timing.165 * either before the insertion or afterwards, depending on timing.
166 */166 */
167static inline int page_cache_get_speculative(struct page *page)167static inline int __page_cache_add_speculative(struct page *page, int count)
168{168{
169#ifdef CONFIG_TINY_RCU169#ifdef CONFIG_TINY_RCU
170# ifdef CONFIG_PREEMPT_COUNT170# ifdef CONFIG_PREEMPT_COUNT
@@ -180,10 +180,10 @@ static inline int page_cache_get_speculative(struct page *page) · 9 unmodified lines
180 * SMP requires.180 * SMP requires.
181 */181 */
182 VM_BUG_ON_PAGE(page_count(page) == 0, page);182 VM_BUG_ON_PAGE(page_count(page) == 0, page);
183 page_ref_inc(page);183 page_ref_add(page, count);
184 184
185#else185#else
186 if (unlikely(!get_page_unless_zero(page))) {186 if (unlikely(!page_ref_add_unless(page, count, 0))) {
187 /*187 /*
188 * Either the page has been freed, or will be freed.188 * Either the page has been freed, or will be freed.
189 * In either case, retry here and the caller should189 * 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
197 return 1;197 return 1;
198}198}
199 199
200/*200static inline int page_cache_get_speculative(struct page *page)
201 * Same as above, but add instead of inc (could just be merged)
202 */
203static inline int page_cache_add_speculative(struct page *page, int count)
204{201{
205 VM_BUG_ON(in_interrupt());202 return __page_cache_add_speculative(page, 1);
206 203}
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);
219 204
220 return 1;205static inline int page_cache_add_speculative(struct page *page, int count)
206{
207 return __page_cache_add_speculative(page, count);
221}208}
222 209
223#ifdef CONFIG_NUMA210#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