Received: by 2002:a05:6358:9144:b0:117:f937:c515 with SMTP id r4csp768776rwr; Wed, 19 Apr 2023 12:50:09 -0700 (PDT) X-Google-Smtp-Source: AKy350YxDv2tAxvGkvHsMUPEh9Y7P3efiVl+zip00HEkfOpHOr9d5GNjzGeGOUldBU7rx4jX2YOV X-Received: by 2002:a17:902:c40a:b0:19b:dbf7:f9ca with SMTP id k10-20020a170902c40a00b0019bdbf7f9camr7967468plk.0.1681933809356; Wed, 19 Apr 2023 12:50:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1681933809; cv=none; d=google.com; s=arc-20160816; b=o1vtiYnSBGjChMYsPG1jbsLEKyHnVWh8kqvhlfYcjcUccHUWJbR3hQ6Rh98xN1UkKF WAJJj84nAiHyNhLCNdWg6K7/1sSMrHEtHg4bnelnEQafn3J0P7KgEypkYVN3UbFzTuJE WLZ1dzizai/Tk66yxRn2ycjexAY2EAcoP3LQIUOhxbava1mpzOlSZLJJtcWby5iVhIIs T4jDgBTvteKDOVvdue9QhTo7HlUsuUWMHb2sHTBv/uhP54SEQen5gtq2VFGuP0pMp9/v VpYTSeXDGnuNm15nGzN/h3xQQIn1iczX3C5AOwyqgncEQlDe0c5XLoKEMpEpBc14nER1 F2MA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=xdUAPCZoCZKyxTXxBNBTgEYlJ+oLtQj3t6vumFGrHXk=; b=z5AjEzpwCBUxPU5NfOu1qYKogJUIyHuO/Hk/MXLRUeYNiwGpXOiO+aiLnEeHGYEvRr aIRK/jzV1N/iCk7kCaTHrAC6vVy+JwENVN+HgAjYtcamDdP7ojA4Lz69OO/jR27Rv/Qt L/+ikLoWvKoqRkuQtFGvGCvncr+zHz9R3U4UODv4gKMXcV7g4mtHBK5sX+lMfvM1ANzt 1Pxfy31raQ85FPbYR1v8oFkH351nBnRAt5dEWKuFXJ2IQpqMsGXg88Z7C01Ozd0in43g 9/ODbC5ob5qN3l3eAE5reszeVzgbPSu/eS0vA14o7X+Iw4s0hHFvH2WUkFTvng6kFfVL w8qA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=Yv+iCzyL; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id ay8-20020a1709028b8800b001a1a7043ec5si15964545plb.243.2023.04.19.12.49.56; Wed, 19 Apr 2023 12:50:09 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=Yv+iCzyL; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230027AbjDSTpf (ORCPT + 99 others); Wed, 19 Apr 2023 15:45:35 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49720 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229542AbjDSTpe (ORCPT ); Wed, 19 Apr 2023 15:45:34 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id F141E1FC3 for ; Wed, 19 Apr 2023 12:45:32 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 85890641F5 for ; Wed, 19 Apr 2023 19:45:32 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id B9E80C433EF; Wed, 19 Apr 2023 19:45:31 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1681933531; bh=ug0VpQZbuLIIcHgv/qpf5I+wi9aKnmeASPKgGIfd2mo=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=Yv+iCzyL9LeLRsYG57Z3orpkDNfmifRvzVjZbaEf0NuAy1RkKQgFCNFID89kf4C9V hdXerFOalds4WN/raivtgQJnaCOP7JyOHwy62ewAx/0llU0UwHLdrAvmfqO81ILQtk Pf+Z/frZbEe6wa9gS1Oy/NbZjMk+yeBnKS6tjVFwwO2rB1av9z0fUyCTwOco3lXthy jWY9FtvYE53vo3llf2+5Vg36dDW+6Th+u0LkSDiY37kTxUoYd9nwCc1W5rH690+3Hy 4JOf8jwXOv/fTqG/0kvV6YX/Y/YEJvoQUeZ5aVdb4WT/R33zhQ9/lSlu8KZFAHcRap ayHReteR/1p6Q== Date: Wed, 19 Apr 2023 12:45:30 -0700 From: Jaegeuk Kim To: Chao Yu Cc: wubo.oduw@gmail.com, linux-kernel@vger.kernel.org, Wu Bo , linux-f2fs-devel@lists.sourceforge.net Subject: Re: [f2fs-dev] [PATCH 1/1] f2fs: allocate trace path buffer from names_cache Message-ID: References: <20230414104308.6591-1-bo.wu@vivo.com> <91a05857-c916-cae5-d61d-bbec6f1ae052@kernel.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Spam-Status: No, score=-7.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 04/19, Jaegeuk Kim wrote: > On 04/19, Chao Yu wrote: > > On 2023/4/19 0:07, Jaegeuk Kim wrote: > > > On 04/18, Chao Yu wrote: > > > > On 2023/4/14 18:43, Wu Bo wrote: > > > > > It would be better to use the dedicated slab to store path. > > > > > > > > > > Signed-off-by: Wu Bo > > > > > --- > > > > > fs/f2fs/file.c | 4 ++-- > > > > > 1 file changed, 2 insertions(+), 2 deletions(-) > > > > > > > > > > diff --git a/fs/f2fs/file.c b/fs/f2fs/file.c > > > > > index 15dabeac4690..27137873958f 100644 > > > > > --- a/fs/f2fs/file.c > > > > > +++ b/fs/f2fs/file.c > > > > > @@ -4361,7 +4361,7 @@ static void f2fs_trace_rw_file_path(struct kiocb *iocb, size_t count, int rw) > > > > > struct inode *inode = file_inode(iocb->ki_filp); > > > > > char *buf, *path; > > > > > - buf = f2fs_kmalloc(F2FS_I_SB(inode), PATH_MAX, GFP_KERNEL); > > > > > + buf = __getname(); > > > > > > > > How about: > > > > > > > > buf = f2fs_kmem_cache_alloc(names_cachep, GFP_KERNEL, NULL, F2FS_I_SB(inode)); > > > > > > This looks like a hack using names_cachep? > > > > names_cachep was exported in fs.h. > > I think that's for __getname() in general, which doesn't indicate you can hack. > No one is using like that. > > $ grep names_cachep fs/* -R > fs/dcache.c:struct kmem_cache *names_cachep __read_mostly; > fs/dcache.c:EXPORT_SYMBOL(names_cachep); > fs/dcache.c: names_cachep = kmem_cache_create_usercopy("names_cache", PATH_MAX, 0, > > $ grep __getname fs/* -R > fs/ceph/mds_client.c: path = __getname(); > fs/cifs/cifsproto.h: return __getname(); > fs/dcache.c:/* SLAB cache for __getname() consumers */ > fs/d_path.c: char *page = __getname(); > fs/exfat/dir.c: nb->lfn = __getname(); > fs/f2fs/file.c: buf = __getname(); > fs/fat/dir.c: *unicode = __getname(); > fs/fat/namei_vfat.c: uname = __getname(); > fs/hostfs/hostfs_kern.c: char *name = __getname(); > fs/namei.c: result = __getname(); > fs/namei.c: result = __getname(); > fs/ntfs3/dir.c: name = __getname(); > fs/ntfs3/xattr.c: buf = __getname(); > fs/ntfs3/inode.c: new_de = __getname(); > fs/ntfs3/inode.c: de = __getname(); > fs/ntfs3/inode.c: de = __getname(); > fs/ntfs3/namei.c: struct cpu_str *uni = __getname(); > fs/ntfs3/namei.c: de = __getname(); > fs/ntfs3/namei.c: struct cpu_str *uni = __getname(); > fs/ntfs3/namei.c: uni = __getname(); > fs/ntfs3/namei.c: uni1 = __getname(); > fs/vboxsf/utils.c: * Returns a shfl_string allocated through __getname (must be freed using > fs/vboxsf/utils.c: buf = __getname(); > fs/vboxsf/utils.c: shfl_path = __getname(); > > > > > > Using f2fs_kmem_cache_alloc is able to inject malloc error. > > > But here is a trace event, is it ok to inject error in a trace path? > > > > Yes, the fail path handling is very simple, so it's fine to leave it > > as it is. > > > > Reviewed-by: Chao Yu > > What is this for? > If we want to keep the error injection, how about this? Signed-off-by: Wu Bo Signed-off-by: Jaegeuk Kim --- fs/f2fs/f2fs.h | 13 +++++++++++++ fs/f2fs/file.c | 4 ++-- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/fs/f2fs/f2fs.h b/fs/f2fs/f2fs.h index 6cae94d51821..d87044516fe9 100644 --- a/fs/f2fs/f2fs.h +++ b/fs/f2fs/f2fs.h @@ -3347,6 +3347,19 @@ static inline void *f2fs_kmalloc(struct f2fs_sb_info *sbi, return kmalloc(size, flags); } +static inline void *f2fs_getname(struct f2fs_sb_info *sbi) +{ + if (time_to_inject(sbi, FAULT_KMALLOC)) + return NULL; + + return __getname(); +} + +static inline void f2fs_putname(char *buf) +{ + __putname(buf); +} + static inline void *f2fs_kzalloc(struct f2fs_sb_info *sbi, size_t size, gfp_t flags) { diff --git a/fs/f2fs/file.c b/fs/f2fs/file.c index 1b4411271f54..5ac53d2627d2 100644 --- a/fs/f2fs/file.c +++ b/fs/f2fs/file.c @@ -4372,7 +4372,7 @@ static void f2fs_trace_rw_file_path(struct kiocb *iocb, size_t count, int rw) struct inode *inode = file_inode(iocb->ki_filp); char *buf, *path; - buf = f2fs_kmalloc(F2FS_I_SB(inode), PATH_MAX, GFP_KERNEL); + buf = f2fs_getname(F2FS_I_SB(inode)); if (!buf) return; path = dentry_path_raw(file_dentry(iocb->ki_filp), buf, PATH_MAX); @@ -4385,7 +4385,7 @@ static void f2fs_trace_rw_file_path(struct kiocb *iocb, size_t count, int rw) trace_f2fs_dataread_start(inode, iocb->ki_pos, count, current->pid, path, current->comm); free_buf: - kfree(buf); + f2fs_putname(buf); } static ssize_t f2fs_file_read_iter(struct kiocb *iocb, struct iov_iter *to) -- 2.40.0.634.g4ca3ef3211-goog