diff mbox series

[1/8] mm/vmscan: remove redundant folio_test_swapbacked check when folio is file lru

Message ID 20220329132619.18689-2-linmiaohe@huawei.com (mailing list archive)
State New
Headers show
Series A few cleanup and fixup patches for migration | expand

Commit Message

Miaohe Lin March 29, 2022, 1:26 p.m. UTC
When folio is file lru, folio_test_swapbacked is guaranteed to be true. So
it's unnecessary to check it here again. No functional change intended.

Signed-off-by: Miaohe Lin <linmiaohe@huawei.com>
---
 mm/vmscan.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

Comments

Matthew Wilcox March 29, 2022, 1:46 p.m. UTC | #1
On Tue, Mar 29, 2022 at 09:26:12PM +0800, Miaohe Lin wrote:
> When folio is file lru, folio_test_swapbacked is guaranteed to be true. So
> it's unnecessary to check it here again. No functional change intended.

ummm ... is your logic right here?  The condition is:

	if (!a || (b && !c))

I don't see how it follows that a => c means we can do any
simplification at all.

> Signed-off-by: Miaohe Lin <linmiaohe@huawei.com>
> ---
>  mm/vmscan.c | 3 +--
>  1 file changed, 1 insertion(+), 2 deletions(-)
> 
> diff --git a/mm/vmscan.c b/mm/vmscan.c
> index 1678802e03e7..7c1a9713bfc9 100644
> --- a/mm/vmscan.c
> +++ b/mm/vmscan.c
> @@ -1434,8 +1434,7 @@ static void folio_check_dirty_writeback(struct folio *folio,
>  	 * Anonymous pages are not handled by flushers and must be written
>  	 * from reclaim context. Do not stall reclaim based on them
>  	 */
> -	if (!folio_is_file_lru(folio) ||
> -	    (folio_test_anon(folio) && !folio_test_swapbacked(folio))) {
> +	if (!folio_is_file_lru(folio) || folio_test_anon(folio)) {
>  		*dirty = false;
>  		*writeback = false;
>  		return;
> -- 
> 2.23.0
> 
>
Miaohe Lin March 30, 2022, 1:46 a.m. UTC | #2
On 2022/3/29 21:46, Matthew Wilcox wrote:
> On Tue, Mar 29, 2022 at 09:26:12PM +0800, Miaohe Lin wrote:
>> When folio is file lru, folio_test_swapbacked is guaranteed to be true. So
>> it's unnecessary to check it here again. No functional change intended.
> 
> ummm ... is your logic right here?  The condition is:
> 
> 	if (!a || (b && !c))
> 

Because a is !c, so c is !a. Then we have:

!a || (b && !c) ==> !a || (b && !!a) ==> !a || (b && a) ==> !a || b.

Or am I miss something?

Thanks.

> I don't see how it follows that a => c means we can do any
> simplification at all.
> 
>> Signed-off-by: Miaohe Lin <linmiaohe@huawei.com>
>> ---
>>  mm/vmscan.c | 3 +--
>>  1 file changed, 1 insertion(+), 2 deletions(-)
>>
>> diff --git a/mm/vmscan.c b/mm/vmscan.c
>> index 1678802e03e7..7c1a9713bfc9 100644
>> --- a/mm/vmscan.c
>> +++ b/mm/vmscan.c
>> @@ -1434,8 +1434,7 @@ static void folio_check_dirty_writeback(struct folio *folio,
>>  	 * Anonymous pages are not handled by flushers and must be written
>>  	 * from reclaim context. Do not stall reclaim based on them
>>  	 */
>> -	if (!folio_is_file_lru(folio) ||
>> -	    (folio_test_anon(folio) && !folio_test_swapbacked(folio))) {
>> +	if (!folio_is_file_lru(folio) || folio_test_anon(folio)) {
>>  		*dirty = false;
>>  		*writeback = false;
>>  		return;
>> -- 
>> 2.23.0
>>
>>
> 
> .
>
Muchun Song March 30, 2022, 8:13 a.m. UTC | #3
On Tue, Mar 29, 2022 at 9:26 PM Miaohe Lin <linmiaohe@huawei.com> wrote:
>
> When folio is file lru, folio_test_swapbacked is guaranteed to be true. So
> it's unnecessary to check it here again. No functional change intended.
>
> Signed-off-by: Miaohe Lin <linmiaohe@huawei.com>
> ---
>  mm/vmscan.c | 3 +--
>  1 file changed, 1 insertion(+), 2 deletions(-)
>
> diff --git a/mm/vmscan.c b/mm/vmscan.c
> index 1678802e03e7..7c1a9713bfc9 100644
> --- a/mm/vmscan.c
> +++ b/mm/vmscan.c
> @@ -1434,8 +1434,7 @@ static void folio_check_dirty_writeback(struct folio *folio,
>          * Anonymous pages are not handled by flushers and must be written
>          * from reclaim context. Do not stall reclaim based on them
>          */
> -       if (!folio_is_file_lru(folio) ||
> -           (folio_test_anon(folio) && !folio_test_swapbacked(folio))) {
> +       if (!folio_is_file_lru(folio) || folio_test_anon(folio)) {

At least your login is no problem since folio_is_file_lru() is equal to
!folio_test_swapbacked().  But the new code is not clear to me.
The old code is easy to understand, e.g. folio_test_anon(folio) &&
!folio_test_swapbacked(folio) tells us that the anon pages which
do not need to be swapped should be skipped. So I'm neutral on
the patch.
Miaohe Lin March 30, 2022, 9:26 a.m. UTC | #4
On 2022/3/30 16:13, Muchun Song wrote:
> On Tue, Mar 29, 2022 at 9:26 PM Miaohe Lin <linmiaohe@huawei.com> wrote:
>>
>> When folio is file lru, folio_test_swapbacked is guaranteed to be true. So
>> it's unnecessary to check it here again. No functional change intended.
>>
>> Signed-off-by: Miaohe Lin <linmiaohe@huawei.com>
>> ---
>>  mm/vmscan.c | 3 +--
>>  1 file changed, 1 insertion(+), 2 deletions(-)
>>
>> diff --git a/mm/vmscan.c b/mm/vmscan.c
>> index 1678802e03e7..7c1a9713bfc9 100644
>> --- a/mm/vmscan.c
>> +++ b/mm/vmscan.c
>> @@ -1434,8 +1434,7 @@ static void folio_check_dirty_writeback(struct folio *folio,
>>          * Anonymous pages are not handled by flushers and must be written
>>          * from reclaim context. Do not stall reclaim based on them
>>          */
>> -       if (!folio_is_file_lru(folio) ||
>> -           (folio_test_anon(folio) && !folio_test_swapbacked(folio))) {
>> +       if (!folio_is_file_lru(folio) || folio_test_anon(folio)) {
> 
> At least your login is no problem since folio_is_file_lru() is equal to
> !folio_test_swapbacked().  But the new code is not clear to me.
> The old code is easy to understand, e.g. folio_test_anon(folio) &&
> !folio_test_swapbacked(folio) tells us that the anon pages which
> do not need to be swapped should be skipped. So I'm neutral on
> the patch.

Thanks for your comment. The previous one might look more common:
folio_test_anon(folio) && !folio_test_swapbacked(folio) means folio
is MADV_FREE and can be freed without swapping out. And I remove the
unneeded !folio_test_swapbacked(folio) check at the expense of losing
minor readability. If it is not worth doing this, I will drop this
patch.

Thanks.

> 
> .
>
Huang, Ying March 31, 2022, 6:37 a.m. UTC | #5
Muchun Song <songmuchun@bytedance.com> writes:

> On Tue, Mar 29, 2022 at 9:26 PM Miaohe Lin <linmiaohe@huawei.com> wrote:
>>
>> When folio is file lru, folio_test_swapbacked is guaranteed to be true. So
>> it's unnecessary to check it here again. No functional change intended.
>>
>> Signed-off-by: Miaohe Lin <linmiaohe@huawei.com>
>> ---
>>  mm/vmscan.c | 3 +--
>>  1 file changed, 1 insertion(+), 2 deletions(-)
>>
>> diff --git a/mm/vmscan.c b/mm/vmscan.c
>> index 1678802e03e7..7c1a9713bfc9 100644
>> --- a/mm/vmscan.c
>> +++ b/mm/vmscan.c
>> @@ -1434,8 +1434,7 @@ static void folio_check_dirty_writeback(struct folio *folio,
>>          * Anonymous pages are not handled by flushers and must be written
>>          * from reclaim context. Do not stall reclaim based on them
>>          */
>> -       if (!folio_is_file_lru(folio) ||
>> -           (folio_test_anon(folio) && !folio_test_swapbacked(folio))) {
>> +       if (!folio_is_file_lru(folio) || folio_test_anon(folio)) {
>
> At least your login is no problem since folio_is_file_lru() is equal to
> !folio_test_swapbacked().  But the new code is not clear to me.
> The old code is easy to understand, e.g. folio_test_anon(folio) &&
> !folio_test_swapbacked(folio) tells us that the anon pages which
> do not need to be swapped should be skipped.

That is for MADV_FREE pages.  The code is introduced in commit
802a3a92ad7a ("mm: reclaim MADV_FREE pages").

So I think the original code is better.  It's an implementation detail
that folio_is_file_lru() equals !folio_test_swapbacked().  It may be
better to add some comments here for MADV_FREE pages.

> So I'm neutral on the patch.

Best Regards,
Huang, Ying
Miaohe Lin March 31, 2022, 7:44 a.m. UTC | #6
On 2022/3/31 14:37, Huang, Ying wrote:
> Muchun Song <songmuchun@bytedance.com> writes:
> 
>> On Tue, Mar 29, 2022 at 9:26 PM Miaohe Lin <linmiaohe@huawei.com> wrote:
>>>
>>> When folio is file lru, folio_test_swapbacked is guaranteed to be true. So
>>> it's unnecessary to check it here again. No functional change intended.
>>>
>>> Signed-off-by: Miaohe Lin <linmiaohe@huawei.com>
>>> ---
>>>  mm/vmscan.c | 3 +--
>>>  1 file changed, 1 insertion(+), 2 deletions(-)
>>>
>>> diff --git a/mm/vmscan.c b/mm/vmscan.c
>>> index 1678802e03e7..7c1a9713bfc9 100644
>>> --- a/mm/vmscan.c
>>> +++ b/mm/vmscan.c
>>> @@ -1434,8 +1434,7 @@ static void folio_check_dirty_writeback(struct folio *folio,
>>>          * Anonymous pages are not handled by flushers and must be written
>>>          * from reclaim context. Do not stall reclaim based on them
>>>          */
>>> -       if (!folio_is_file_lru(folio) ||
>>> -           (folio_test_anon(folio) && !folio_test_swapbacked(folio))) {
>>> +       if (!folio_is_file_lru(folio) || folio_test_anon(folio)) {
>>
>> At least your login is no problem since folio_is_file_lru() is equal to
>> !folio_test_swapbacked().  But the new code is not clear to me.
>> The old code is easy to understand, e.g. folio_test_anon(folio) &&
>> !folio_test_swapbacked(folio) tells us that the anon pages which
>> do not need to be swapped should be skipped.
> 
> That is for MADV_FREE pages.  The code is introduced in commit
> 802a3a92ad7a ("mm: reclaim MADV_FREE pages").
> 
> So I think the original code is better.  It's an implementation detail
> that folio_is_file_lru() equals !folio_test_swapbacked().  It may be
> better to add some comments here for MADV_FREE pages.
> 

Do you tend to drop this patch or adding a comment with the change in this patch or something else?

Thanks.

>> So I'm neutral on the patch.
> 
> Best Regards,
> Huang, Ying
> .
>
Huang, Ying March 31, 2022, 8:02 a.m. UTC | #7
Miaohe Lin <linmiaohe@huawei.com> writes:

> On 2022/3/31 14:37, Huang, Ying wrote:
>> Muchun Song <songmuchun@bytedance.com> writes:
>> 
>>> On Tue, Mar 29, 2022 at 9:26 PM Miaohe Lin <linmiaohe@huawei.com> wrote:
>>>>
>>>> When folio is file lru, folio_test_swapbacked is guaranteed to be true. So
>>>> it's unnecessary to check it here again. No functional change intended.
>>>>
>>>> Signed-off-by: Miaohe Lin <linmiaohe@huawei.com>
>>>> ---
>>>>  mm/vmscan.c | 3 +--
>>>>  1 file changed, 1 insertion(+), 2 deletions(-)
>>>>
>>>> diff --git a/mm/vmscan.c b/mm/vmscan.c
>>>> index 1678802e03e7..7c1a9713bfc9 100644
>>>> --- a/mm/vmscan.c
>>>> +++ b/mm/vmscan.c
>>>> @@ -1434,8 +1434,7 @@ static void folio_check_dirty_writeback(struct folio *folio,
>>>>          * Anonymous pages are not handled by flushers and must be written
>>>>          * from reclaim context. Do not stall reclaim based on them
>>>>          */
>>>> -       if (!folio_is_file_lru(folio) ||
>>>> -           (folio_test_anon(folio) && !folio_test_swapbacked(folio))) {
>>>> +       if (!folio_is_file_lru(folio) || folio_test_anon(folio)) {
>>>
>>> At least your login is no problem since folio_is_file_lru() is equal to
>>> !folio_test_swapbacked().  But the new code is not clear to me.
>>> The old code is easy to understand, e.g. folio_test_anon(folio) &&
>>> !folio_test_swapbacked(folio) tells us that the anon pages which
>>> do not need to be swapped should be skipped.
>> 
>> That is for MADV_FREE pages.  The code is introduced in commit
>> 802a3a92ad7a ("mm: reclaim MADV_FREE pages").
>> 
>> So I think the original code is better.  It's an implementation detail
>> that folio_is_file_lru() equals !folio_test_swapbacked().  It may be
>> better to add some comments here for MADV_FREE pages.
>> 
>
> Do you tend to drop this patch or adding a comment with the change in this patch or something else?

I suggest to drop the code change and add a comment about MADV_FREE.

Best Regards,
Huang, Ying

> Thanks.
>
>>> So I'm neutral on the patch.
>> 
>> Best Regards,
>> Huang, Ying
>> .
>>
Miaohe Lin March 31, 2022, 8:07 a.m. UTC | #8
On 2022/3/31 16:02, Huang, Ying wrote:
> Miaohe Lin <linmiaohe@huawei.com> writes:
> 
>> On 2022/3/31 14:37, Huang, Ying wrote:
>>> Muchun Song <songmuchun@bytedance.com> writes:
>>>
>>>> On Tue, Mar 29, 2022 at 9:26 PM Miaohe Lin <linmiaohe@huawei.com> wrote:
>>>>>
>>>>> When folio is file lru, folio_test_swapbacked is guaranteed to be true. So
>>>>> it's unnecessary to check it here again. No functional change intended.
>>>>>
>>>>> Signed-off-by: Miaohe Lin <linmiaohe@huawei.com>
>>>>> ---
>>>>>  mm/vmscan.c | 3 +--
>>>>>  1 file changed, 1 insertion(+), 2 deletions(-)
>>>>>
>>>>> diff --git a/mm/vmscan.c b/mm/vmscan.c
>>>>> index 1678802e03e7..7c1a9713bfc9 100644
>>>>> --- a/mm/vmscan.c
>>>>> +++ b/mm/vmscan.c
>>>>> @@ -1434,8 +1434,7 @@ static void folio_check_dirty_writeback(struct folio *folio,
>>>>>          * Anonymous pages are not handled by flushers and must be written
>>>>>          * from reclaim context. Do not stall reclaim based on them
>>>>>          */
>>>>> -       if (!folio_is_file_lru(folio) ||
>>>>> -           (folio_test_anon(folio) && !folio_test_swapbacked(folio))) {
>>>>> +       if (!folio_is_file_lru(folio) || folio_test_anon(folio)) {
>>>>
>>>> At least your login is no problem since folio_is_file_lru() is equal to
>>>> !folio_test_swapbacked().  But the new code is not clear to me.
>>>> The old code is easy to understand, e.g. folio_test_anon(folio) &&
>>>> !folio_test_swapbacked(folio) tells us that the anon pages which
>>>> do not need to be swapped should be skipped.
>>>
>>> That is for MADV_FREE pages.  The code is introduced in commit
>>> 802a3a92ad7a ("mm: reclaim MADV_FREE pages").
>>>
>>> So I think the original code is better.  It's an implementation detail
>>> that folio_is_file_lru() equals !folio_test_swapbacked().  It may be
>>> better to add some comments here for MADV_FREE pages.
>>>
>>
>> Do you tend to drop this patch or adding a comment with the change in this patch or something else?
> 
> I suggest to drop the code change and add a comment about MADV_FREE.

Will do. Thanks.

> 
> Best Regards,
> Huang, Ying
> 
>> Thanks.
>>
>>>> So I'm neutral on the patch.
>>>
>>> Best Regards,
>>> Huang, Ying
>>> .
>>>
> .
>
diff mbox series

Patch

diff --git a/mm/vmscan.c b/mm/vmscan.c
index 1678802e03e7..7c1a9713bfc9 100644
--- a/mm/vmscan.c
+++ b/mm/vmscan.c
@@ -1434,8 +1434,7 @@  static void folio_check_dirty_writeback(struct folio *folio,
 	 * Anonymous pages are not handled by flushers and must be written
 	 * from reclaim context. Do not stall reclaim based on them
 	 */
-	if (!folio_is_file_lru(folio) ||
-	    (folio_test_anon(folio) && !folio_test_swapbacked(folio))) {
+	if (!folio_is_file_lru(folio) || folio_test_anon(folio)) {
 		*dirty = false;
 		*writeback = false;
 		return;