From: Chen Gang <gang.chen@asianux.com>
To: Cyrill Gorcunov <gorcunov@gmail.com>
Cc: Mel Gorman <mgorman@suse.de>,
kosaki.motohiro@jp.fujitsu.com, riel@redhat.com,
hughd@google.com, xemul@parallels.com, rientjes@google.com,
Wanpeng Li <liwanp@linux.vnet.ibm.com>,
Andrew Morton <akpm@linux-foundation.org>,
linux-mm@kvack.org,
"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH 0/3] mm: mempolicy: the failure processing about mpol_to_str()
Date: Tue, 20 Aug 2013 15:51:45 +0800 [thread overview]
Message-ID: <52132011.60501@asianux.com> (raw)
In-Reply-To: <52131F48.1030002@asianux.com>
On 08/20/2013 03:48 PM, Chen Gang wrote:
> On 08/20/2013 02:47 PM, Cyrill Gorcunov wrote:
>> On Tue, Aug 20, 2013 at 01:41:40PM +0800, Chen Gang wrote:
>>>
>>>> sure you'll have to change shmem_show_mpol statement to return int code.
>>>> Won't this be more short and convenient?
>>>>
>>>>
>>>
>>> Hmm... if return -ENOSPC, in common processing, it still need continue
>>> (but need let outside know about the string truncation).
>>>
>>> So I still suggest to give more check for it.
>>
>> I still don't like adding additional code like
>>
>> + ret = mpol_to_str(buffer, sizeof(buffer), mpol);
>> + if (ret < 0)
>> + switch (ret) {
>> + case -ENOSPC:
>> + printk(KERN_WARNING
>> + "in %s: string is truncated in mpol_to_str().\n",
>> + __func__);
Oh, that need 'break' in my original patch. :-)
>> + default:
>> + printk(KERN_ERR
>> + "in %s: call mpol_to_str() fail, errcode: %d. buffer: %p, size: %zu, pol: %p\n",
>> + __func__, ret, buffer, sizeof(buffer), mpol);
>> + return;
>> + }
>>
>> this code is pretty neat for debugging purpose I think but in most case (if
>> only I've not missed something obvious) it simply won't be the case.
>>
>
> For mpol_to_str(), it is for printing string, I suggest to fill buffer
> as full as possible like another printing string functions, -ENOSPC is
> not critical error, callers may can bear it, and still want to continue.
>
> For 2 callers, I still suggest to process '-ENOSPC' and continue, it is
> really not a critical error, they can continue.
>
> For the 'default' error processing:
>
> I still suggest to 'printk' in shmem_show_mpol(), because when failure occurs, it has no return value to mark the failure to upper caller.
> Hmm... but for show_numa_map(), may remove the 'printk', only return the error code is OK. :-)
>
>
> Thanks.
>
>> Won't somthing like below do the same but with smaller code change?
>> Note I've not even compiled it but it shows the idea.
>> ---
>> fs/proc/task_mmu.c | 4 +++-
>> mm/shmem.c | 17 +++++++++--------
>> 2 files changed, 12 insertions(+), 9 deletions(-)
>>
>> Index: linux-2.6.git/fs/proc/task_mmu.c
>> ===================================================================
>> --- linux-2.6.git.orig/fs/proc/task_mmu.c
>> +++ linux-2.6.git/fs/proc/task_mmu.c
>> @@ -1402,8 +1402,10 @@ static int show_numa_map(struct seq_file
>> walk.mm = mm;
>>
>> pol = get_vma_policy(task, vma, vma->vm_start);
>> - mpol_to_str(buffer, sizeof(buffer), pol);
>> + n = mpol_to_str(buffer, sizeof(buffer), pol);
>> mpol_cond_put(pol);
>> + if (n < 0)
>> + return n;
>>
>> seq_printf(m, "%08lx %s", vma->vm_start, buffer);
>>
>> Index: linux-2.6.git/mm/shmem.c
>> ===================================================================
>> --- linux-2.6.git.orig/mm/shmem.c
>> +++ linux-2.6.git/mm/shmem.c
>> @@ -883,16 +883,20 @@ redirty:
>>
>> #ifdef CONFIG_NUMA
>> #ifdef CONFIG_TMPFS
>> -static void shmem_show_mpol(struct seq_file *seq, struct mempolicy *mpol)
>> +static int shmem_show_mpol(struct seq_file *seq, struct mempolicy *mpol)
>> {
>> char buffer[64];
>> + int ret;
>>
>> if (!mpol || mpol->mode == MPOL_DEFAULT)
>> - return; /* show nothing */
>> + return 0; /* show nothing */
>>
>> - mpol_to_str(buffer, sizeof(buffer), mpol);
>> + ret = mpol_to_str(buffer, sizeof(buffer), mpol);
>> + if (ret < 0)
>> + return ret;
>>
>> seq_printf(seq, ",mpol=%s", buffer);
>> + return 0;
>> }
>>
>> static struct mempolicy *shmem_get_sbmpol(struct shmem_sb_info *sbinfo)
>> @@ -951,9 +955,7 @@ static struct page *shmem_alloc_page(gfp
>> }
>> #else /* !CONFIG_NUMA */
>> #ifdef CONFIG_TMPFS
>> -static inline void shmem_show_mpol(struct seq_file *seq, struct mempolicy *mpol)
>> -{
>> -}
>> +static inline int shmem_show_mpol(struct seq_file *seq, struct mempolicy *mpol) { return 0; }
>> #endif /* CONFIG_TMPFS */
>>
>> static inline struct page *shmem_swapin(swp_entry_t swap, gfp_t gfp,
>> @@ -2577,8 +2579,7 @@ static int shmem_show_options(struct seq
>> if (!gid_eq(sbinfo->gid, GLOBAL_ROOT_GID))
>> seq_printf(seq, ",gid=%u",
>> from_kgid_munged(&init_user_ns, sbinfo->gid));
>> - shmem_show_mpol(seq, sbinfo->mpol);
>> - return 0;
>> + return shmem_show_mpol(seq, sbinfo->mpol);
>> }
>> #endif /* CONFIG_TMPFS */
>>
>>
>>
>
>
--
Chen Gang
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>
next prev parent reply other threads:[~2013-08-20 7:52 UTC|newest]
Thread overview: 58+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-08-20 3:56 Chen Gang
2013-08-20 3:57 ` [PATCH 1/3] mm/mempolicy.c: still fill buffer as full as possible when buffer space is not enough in mpol_to_str() Chen Gang
2013-08-20 3:58 ` [PATCH 2/3] fs/proc/task_mmu.c: check the return value of mpol_to_str() Chen Gang
2013-08-20 3:59 ` [PATCH 3/3] mm/shmem.c: " Chen Gang
2013-08-20 5:30 ` [PATCH 0/3] mm: mempolicy: the failure processing about mpol_to_str() Cyrill Gorcunov
2013-08-20 5:41 ` Chen Gang
2013-08-20 6:47 ` Cyrill Gorcunov
2013-08-20 7:48 ` Chen Gang
2013-08-20 7:51 ` Chen Gang [this message]
2013-08-20 8:09 ` Chen Gang
2013-08-20 8:13 ` Chen Gang F T
2013-08-20 8:20 ` Chen Gang
2013-08-20 8:25 ` Cyrill Gorcunov
2013-08-20 8:31 ` Chen Gang
2013-08-21 2:21 ` [PATCH 0/3] mm: shmem: check the return value of mpol_to_str() Chen Gang
2013-08-21 2:22 ` [PATCH 1/3] fs/proc/task_mmu.c: " Chen Gang
2013-08-21 2:23 ` [PATCH 2/3] mm/shmem.c: let shmem_show_mpol() return value Chen Gang
2013-08-21 2:24 ` [PATCH 3/3] mm/shmem.c: check the return value of mpol_to_str() Chen Gang
2013-08-21 22:03 ` [PATCH 2/3] mm/shmem.c: let shmem_show_mpol() return value Andrew Morton
2013-08-22 0:52 ` Chen Gang
2013-08-22 1:04 ` [PATCH] mm/shmem.c: check the return value of mpol_to_str() Chen Gang
2013-09-03 5:32 ` Chen Gang
2013-09-05 0:24 ` [PATCH v2] " Chen Gang
2013-09-09 20:30 ` David Rientjes
2013-09-10 0:47 ` Chen Gang
2013-09-10 6:43 ` David Rientjes
2013-09-10 7:01 ` Chen Gang
2013-09-12 0:33 ` David Rientjes
2013-09-12 2:19 ` KOSAKI Motohiro
2013-09-12 3:13 ` Chen Gang
2013-09-13 21:12 ` David Rientjes
2013-09-14 2:51 ` KOSAKI Motohiro
2013-09-16 3:27 ` Chen Gang
2013-09-16 20:13 ` David Rientjes
2013-09-17 0:45 ` Chen Gang
2013-09-17 22:51 ` David Rientjes
2013-09-18 1:20 ` Chen Gang
2013-09-12 3:02 ` Chen Gang
2013-09-12 18:19 ` KOSAKI Motohiro
2013-09-13 2:23 ` Chen Gang
2013-09-13 16:50 ` KOSAKI Motohiro
2013-09-16 2:55 ` Chen Gang
2013-09-16 16:16 ` KOSAKI Motohiro
2013-09-17 1:10 ` Chen Gang
2013-09-17 22:53 ` David Rientjes
2013-09-18 1:37 ` Chen Gang
2013-09-18 22:17 ` David Rientjes
2013-09-13 21:14 ` David Rientjes
2013-09-16 3:17 ` Chen Gang
2013-09-25 2:58 ` [patch] mm, mempolicy: make mpol_to_str robust and always succeed David Rientjes
2013-09-25 3:11 ` Dave Jones
2013-09-25 3:18 ` David Rientjes
2013-09-25 3:25 ` Dave Jones
2013-09-25 17:58 ` David Rientjes
2013-09-25 21:30 ` Andrew Morton
2013-09-25 22:06 ` David Rientjes
2013-08-21 5:31 ` [PATCH 0/3] mm: shmem: check the return value of mpol_to_str() Cyrill Gorcunov
2013-08-21 5:48 ` Chen Gang
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=52132011.60501@asianux.com \
--to=gang.chen@asianux.com \
--cc=akpm@linux-foundation.org \
--cc=gorcunov@gmail.com \
--cc=hughd@google.com \
--cc=kosaki.motohiro@jp.fujitsu.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=liwanp@linux.vnet.ibm.com \
--cc=mgorman@suse.de \
--cc=riel@redhat.com \
--cc=rientjes@google.com \
--cc=xemul@parallels.com \
/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