From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mailgw.kylinos.cn (mailgw.kylinos.cn [124.126.103.232]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 0D0102DF68 for ; Fri, 10 Apr 2026 01:45:45 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=124.126.103.232 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1775785548; cv=none; b=UIyKvRwh7c4V625IvmpyonkOYMQABZVM63Q9MD4OPSL+LgWIFU+QMDOYKjKZ57VjpLtYmxQk+KYj+hZWLcUCoGyVLXbOon6qlhCW2KmYoGqPt3D0xsYbPHa2wnqg+idXhnFJRrp2U1GQrx9ISmqf5N78fO8zEmfuz/KsyHDOq/Q= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1775785548; c=relaxed/simple; bh=Icac/naTSx/+1Kr25qac5xmSa25exaAWaNOccCyThkE=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=CzS3XYwQ7QmITmOQAdtmZOU2fRhI054L1gUFMkPSZi2tFilP3miYJztNyDMCId3tWocEzM8rdx0A1T0C6UONOnSlQ0p/hz0wcQhQxgn7VehAH39zo8m0axZmFecdKG+I4T1ZoroqfhCaGLqDYgTAxTy22IV+Azfl2D/Zdg17ZDw= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=kylinos.cn; spf=pass smtp.mailfrom=kylinos.cn; arc=none smtp.client-ip=124.126.103.232 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=kylinos.cn Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=kylinos.cn X-UUID: fae9241a347e11f1aa26b74ffac11d73-20260410 X-CTIC-Tags: HR_CC_COUNT, HR_CC_DOMAIN_COUNT, HR_CC_NO_NAME, HR_CTE_MISS, HR_CTT_TXT HR_DATE_H, HR_DATE_WKD, HR_DATE_ZONE, HR_FROM_NAME, HR_SJ_DIGIT_LEN HR_SJ_LANG, HR_SJ_LEN, HR_SJ_LETTER, HR_SJ_NOR_SYM, HR_SJ_PHRASE HR_SJ_PHRASE_LEN, HR_SJ_PRE_RE, HR_SJ_WS, HR_TO_COUNT, HR_TO_DOMAIN_COUNT HR_TO_NAME, IP_TRUSTED, SRC_TRUSTED, DN_TRUSTED, SA_EXISTED SN_EXISTED, SPF_NOPASS, DKIM_NOPASS, DMARC_NOPASS, CIE_BAD CIE_GOOD, CIE_GOOD_SPF, GTI_FG_BS, GTI_RG_INFO, GTI_C_BU AMN_GOOD, ABX_MISS_RDNS X-CID-P-RULE: Release_Ham X-CID-O-INFO: VERSION:1.3.12,REQID:c0a3695b-2827-4ab0-be2c-583600168ecd,IP:10, URL:0,TC:0,Content:0,EDM:0,RT:0,SF:-5,FILE:0,BULK:0,RULE:Release_Ham,ACTIO N:release,TS:5 X-CID-INFO: VERSION:1.3.12,REQID:c0a3695b-2827-4ab0-be2c-583600168ecd,IP:10,UR L:0,TC:0,Content:0,EDM:0,RT:0,SF:-5,FILE:0,BULK:0,RULE:Release_Ham,ACTION: release,TS:5 X-CID-META: VersionHash:e7bac3a,CLOUDID:2de7d952e5399516536cf2261e99e66d,BulkI D:260402190217GRSRXCIQ,BulkQuantity:7,Recheck:0,SF:17|19|64|66|78|80|81|82 |83|102|127|841|850|898,TC:nil,Content:0|15|50,EDM:-3,IP:-2,URL:0,File:nil ,RT:nil,Bulk:40,QS:nil,BEC:nil,COL:0,OSI:0,OSA:0,AV:0,LES:1,SPR:NO,DKR:0,D KP:0,BRR:0,BRE:0,ARC:0 X-CID-BVR: 2,SSN|SDN X-CID-BAS: 2,SSN|SDN,0,_ X-CID-FACTOR: TF_CID_SPAM_SNR,TF_CID_SPAM_FAS,TF_CID_SPAM_FSD X-CID-RHF: D41D8CD98F00B204E9800998ECF8427E X-UUID: fae9241a347e11f1aa26b74ffac11d73-20260410 X-User: duanchenghao@kylinos.cn Received: from localhost [(183.242.174.22)] by mailgw.kylinos.cn (envelope-from ) (Generic MTA with TLSv1.3 TLS_AES_256_GCM_SHA384 256/256) with ESMTP id 1494716942; Fri, 10 Apr 2026 09:45:40 +0800 Date: Fri, 10 Apr 2026 09:45:37 +0800 From: Chenghao Duan To: Pratyush Yadav Cc: pasha.tatashin@soleen.com, rppt@kernel.org, akpm@linux-foundation.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org, jianghaoran@kylinos.cn Subject: Re: [PATCH v3 2/7] mm/memfd_luo: optimize shmem_recalc_inode calls in retrieve path Message-ID: <20260410014537.GA28528@chenghao-pc> References: <20260326084727.118437-1-duanchenghao@kylinos.cn> <20260326084727.118437-3-duanchenghao@kylinos.cn> <2vxz8qb5hbgz.fsf@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: <2vxz8qb5hbgz.fsf@kernel.org> On Thu, Apr 02, 2026 at 11:02:04AM +0000, Pratyush Yadav wrote: > On Thu, Mar 26 2026, Chenghao Duan wrote: > > > Move shmem_recalc_inode() out of the loop in memfd_luo_retrieve_folios() > > to improve performance when restoring large memfds. > > > > Currently, shmem_recalc_inode() is called for each folio during restore, > > which is O(n) expensive operations. This patch collects the number of > > successfully added folios and calls shmem_recalc_inode() once after the > > loop completes, reducing complexity to O(1). > > > > Additionally, fix the error path to also call shmem_recalc_inode() for > > the folios that were successfully added before the error occurred. > > > > Reviewed-by: Pasha Tatashin > > Signed-off-by: Chenghao Duan > > Reviewed-by: Pratyush Yadav > > BTW, can we also do the same for shmem_inode_acct_blocks() it the call > to it can also be aggregated in the same way? You don't have to do it in > this series, but possibly as a follow up. > Thanks for pointing that out. We can move shmem_recalc_inode() outside the loop for aggregation, as it performs a single inode state update for the folios. In contrast, shmem_inode_acct_blocks() is a validation step for resource reservation, quota, and block accounting. Since it can fail on its own, aggregating it outside the loop would complicate the error handling and rollback paths, especially when only a subset of folios have been restored. BRs Chenghao > [...] > > -- > Regards, > Pratyush Yadav