Linux filesystem development
 help / color / mirror / Atom feed
From: David Hildenbrand <david@redhat.com>
To: Liu Ye <liuyerd@163.com>, akpm@linux-foundation.org
Cc: willy@infradead.org, ran.xiaokai@zte.com.cn,
	dan.carpenter@linaro.org, linux-kernel@vger.kernel.org,
	linux-fsdevel@vger.kernel.org, Liu Ye <liuye@kylinos.cn>
Subject: Re: [PATCH] fs/proc/page: Refactoring to reduce code duplication.
Date: Mon, 17 Mar 2025 10:18:28 +0100	[thread overview]
Message-ID: <4a336393-6cf3-4053-8137-c6d724c3cb5f@redhat.com> (raw)
In-Reply-To: <2ecdf349-779f-43d5-ae3d-55d973ea50e9@163.com>

On 17.03.25 10:13, Liu Ye wrote:
> 
> 在 2025/3/17 16:56, David Hildenbrand 写道:
>> On 17.03.25 09:01, Liu Ye wrote:
>>> From: Liu Ye <liuye@kylinos.cn>
>>>
>>> The function kpageflags_read and kpagecgroup_read is quite similar
>>> to kpagecount_read. Consider refactoring common code into a helper
>>> function to reduce code duplication.
>>>
>>> Signed-off-by: Liu Ye <liuye@kylinos.cn>
>>> ---
>>>    fs/proc/page.c | 158 ++++++++++++++++---------------------------------
>>>    1 file changed, 50 insertions(+), 108 deletions(-)
>>>
>>> diff --git a/fs/proc/page.c b/fs/proc/page.c
>>> index a55f5acefa97..f413016ebe67 100644
>>> --- a/fs/proc/page.c
>>> +++ b/fs/proc/page.c
>>> @@ -37,19 +37,17 @@ static inline unsigned long get_max_dump_pfn(void)
>>>    #endif
>>>    }
>>>    -/* /proc/kpagecount - an array exposing page mapcounts
>>> - *
>>> - * Each entry is a u64 representing the corresponding
>>> - * physical page mapcount.
>>> - */
>>> -static ssize_t kpagecount_read(struct file *file, char __user *buf,
>>> -                 size_t count, loff_t *ppos)
>>> +static ssize_t kpage_read(struct file *file, char __user *buf,
>>> +        size_t count, loff_t *ppos,
>>> +        u64 (*get_page_info)(struct page *))
>>
>> Can we just indicate using an enum which operation to perform, so we can avoid having+passing these functions?
>>
> Like this? Good idea, I'll send a new patch later.
> 
> enum kpage_operation {
>      KPAGE_FLAGS,
>      KPAGE_COUNT,
>      KPAGE_CGROUP,
> };
> 
> static u64 get_page_info(struct page *page, enum kpage_operation op)
> {
>      switch (op) {
>      case KPAGE_FLAGS:
>          return stable_page_flags(page);
>      case KPAGE_COUNT:
>          return page_count(page);
>      case KPAGE_CGROUP:
>          return page_cgroup_ino(page);
>      default:
>          return 0;
>      }
> }


Likely it's best to inline get_page_info() into kpage_read() to just get 
rid of it.


-- 
Cheers,

David / dhildenb


  reply	other threads:[~2025-03-17  9:18 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-03-17  8:01 [PATCH] fs/proc/page: Refactoring to reduce code duplication Liu Ye
2025-03-17  8:56 ` David Hildenbrand
2025-03-17  9:13   ` Liu Ye
2025-03-17  9:18     ` David Hildenbrand [this message]
2025-03-17  9:31       ` Liu Ye

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=4a336393-6cf3-4053-8137-c6d724c3cb5f@redhat.com \
    --to=david@redhat.com \
    --cc=akpm@linux-foundation.org \
    --cc=dan.carpenter@linaro.org \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=liuye@kylinos.cn \
    --cc=liuyerd@163.com \
    --cc=ran.xiaokai@zte.com.cn \
    --cc=willy@infradead.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox