From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 0A022C83F1A for ; Fri, 11 Jul 2025 07:51:12 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id A37026B009D; Fri, 11 Jul 2025 03:51:11 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id A0E936B009E; Fri, 11 Jul 2025 03:51:11 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 94C4E6B00A0; Fri, 11 Jul 2025 03:51:11 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id 876FC6B009D for ; Fri, 11 Jul 2025 03:51:11 -0400 (EDT) Received: from smtpin18.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id 0CA8A828E6 for ; Fri, 11 Jul 2025 07:51:11 +0000 (UTC) X-FDA: 83651213142.18.D5DADFC Received: from mail-yb1-f181.google.com (mail-yb1-f181.google.com [209.85.219.181]) by imf09.hostedemail.com (Postfix) with ESMTP id 33C8914000C for ; Fri, 11 Jul 2025 07:51:09 +0000 (UTC) Authentication-Results: imf09.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=aIpBJiT8; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf09.hostedemail.com: domain of hughd@google.com designates 209.85.219.181 as permitted sender) smtp.mailfrom=hughd@google.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1752220269; a=rsa-sha256; cv=none; b=E8uTlX0NRh+uAqrUa3Zl26+pwl9fsd03Hl/VDmdd2lVwAN5NHBIkyXg/MYJS5or3yQJ6C+ 3YUQD+/s0DX4vsTeNC6nrS7EyFlir5uTFE5644kSuJGi/EPKumHmxwuFoX5E/V/WZstRNS vdNyTsB/1e1mbFkWJxk3ddvN6F8P9nI= ARC-Authentication-Results: i=1; imf09.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=aIpBJiT8; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf09.hostedemail.com: domain of hughd@google.com designates 209.85.219.181 as permitted sender) smtp.mailfrom=hughd@google.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1752220269; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=yv2N8uYuCEeR1Mb8vyZY91PaDSqMqUw0s6HPE4+mQq8=; b=p59Rck5XlP4SJ/qZez3RUg54vlLB9spoTBqnh8OspRqL/tr1fPq8gbSY1tsEUWN1wovuG2 HORF1YhwCbUDGXFWM2avNHMbVV/BWsXQn1hP7i97cBbs8cpJCriEFhsROHXx+KU5zagLvG g/3+JJYpn+qwYN0a067bAA+ge5LeJHc= Received: by mail-yb1-f181.google.com with SMTP id 3f1490d57ef6-e8b3ec5c82eso2420154276.0 for ; Fri, 11 Jul 2025 00:51:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1752220268; x=1752825068; darn=kvack.org; h=mime-version:references:message-id:in-reply-to:subject:cc:to:from :date:from:to:cc:subject:date:message-id:reply-to; bh=yv2N8uYuCEeR1Mb8vyZY91PaDSqMqUw0s6HPE4+mQq8=; b=aIpBJiT8JAQ7unhJaB7cMUBzBNEj8C4X/oqWepG+eLbzawYph3WcxKQXWAcRULEo/f JTwgbgYhRw/pf25GWnYNR2hi80FZduHGOBfT7rJkIQgcqZVJLDMulPAGyKhBKZwUp8RP F+wQnd6kQeKmydCET09OIs/rkD5+joIdHR5+hcAHT/NT2oo9eZOIg0pOKljgKG2ACsu2 YuwdtMFfKAfOrH+6F15bCbDpLbvDqyfrAQ99S6uayHJncTaRApKABq2E16mSmVUX31yB zmEmTEor+49UtsSgl2ERX4rkN2DC/gYoX/vWJd6zX+eDsTiLYON8mmuNnEL/X3rR40vN u5sg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1752220268; x=1752825068; h=mime-version:references:message-id:in-reply-to:subject:cc:to:from :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=yv2N8uYuCEeR1Mb8vyZY91PaDSqMqUw0s6HPE4+mQq8=; b=ciS6SAXLzrOJg316PPuJQ3sYGCQafYSNduj7cq8THl/rsDzqNgZYZS0wemAs9HztiM eqSm7iLVxRehqKtZvqLVpCstpJJylVwgF/WFtMkR1OrpGXlRZYC8mPhKF3wtN0OLFXdi K89T4nPhMj3QU6oEz8TEK+bmJnqt0ZZfbHZaumr3JwqIkswFVk8Hsv39FutOpR0pKk0D UVoOFvUQRSbBs4O/HeLPvUzlFE14oza8O8fG261cjlzdg24TwqD39V9Ivu+DjM+BdSeD WSz1trNJtsXNrXF3lQDmtvc0oRBWC4491sQADm33Az8Bgdbuj8r+qdKDa+Byps/E3CQf tD8A== X-Forwarded-Encrypted: i=1; AJvYcCUqhjZbBIj4zcyOW72SvZ6OY1PvtmKtVQFN35mvfzV/OfueDHGOZ2OoRt1/Hxkpw8vjWAkQUO0hLg==@kvack.org X-Gm-Message-State: AOJu0Yy5cGwRbb85sdAtHQLvR0rXNG+ONnE3kGe42nHT/fMqreG+l/0k zmGoxJvk0NC41PGuOXMin55ojLzUzRIDLTHdupjiXXG8tuOkGnaJLRYaszineWB8dw== X-Gm-Gg: ASbGncum8Lcp3+/o9K/qmk0T3AS4g5nyQMs+NB3zkjCGguaUnnTpTVEW7ZdgH4XiEGa mWo27jZvhMqqf6BGW2vLIdJy7snxUN8PCmaa5qlerTIiTGr1VklYZe6zovK9EnOlW7lYC1d5okA arbpkcX9WNU91cYrdz93VBbmfLkQkmz2/zkKPztPtxDdpu/8z7MV0HAv5AShN1tsz+pkUyFSkuW 5MVbcFXx1ik7zymf0iAU6bV+WlcSJIWtmeyCDRssvQPWbjuqwVa3lmp9OVzlStgw2fGCRxVpDZX 6F1GOfglHW+VAqf6SH+SZfQ3myXMZs4Q2/GEW5tnsnE7QxNax3/WLXzQp2joT7StGA78EahmL3s Q7pF/G8SjR+htauKqLVRcAL7jIZOrsGCpbWVB0/GRuN/KNP49ioMKK7bWXICVPAVKhlsnuY9pe/ 0qPhdiPx8= X-Google-Smtp-Source: AGHT+IG1tFUqUnlRX29tudR/1UfADbo5Kv4RyNaJf6P+3TOWwYOh+9+0Yg/yoO/8lgr3zeQh3SQvfw== X-Received: by 2002:a05:690c:62c1:b0:712:cc11:aff with SMTP id 00721157ae682-717c159da24mr100351127b3.11.1752220267799; Fri, 11 Jul 2025 00:51:07 -0700 (PDT) Received: from darker.attlocal.net (172-10-233-147.lightspeed.sntcca.sbcglobal.net. [172.10.233.147]) by smtp.gmail.com with ESMTPSA id 00721157ae682-717d11f9659sm4294687b3.25.2025.07.11.00.51.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 11 Jul 2025 00:51:06 -0700 (PDT) Date: Fri, 11 Jul 2025 00:50:55 -0700 (PDT) From: Hugh Dickins To: Baolin Wang cc: Hugh Dickins , Brian Foster , linux-mm@kvack.org, Matthew Wilcox , Usama Arif Subject: Re: [PATCH] tmpfs: zero post-eof folio range on file extension In-Reply-To: <0224ed0f-d207-4c79-8c9d-f4915a91c11d@linux.alibaba.com> Message-ID: References: <20250625184930.269727-1-bfoster@redhat.com> <297e44e9-1b58-d7c4-192c-9408204ab1e3@google.com> <67f0461b-3359-41e7-a7cd-b059cbef4154@linux.alibaba.com> <097c0b07-1f43-51c3-3591-aaa2015226c2@google.com> <0224ed0f-d207-4c79-8c9d-f4915a91c11d@linux.alibaba.com> MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII X-Rspamd-Queue-Id: 33C8914000C X-Stat-Signature: 1e9sf7q3e6scu7xdye6sxh8ojm3accdg X-Rspam-User: X-Rspamd-Server: rspam10 X-HE-Tag: 1752220269-175359 X-HE-Meta: U2FsdGVkX183Ga5N4JIiZRhuEq5S2eca61fS7XkrnUgjaQX6qlUFToqr1xP4MgXeM+YqZtqSGyP1SmKfSYBMKI7za4FTWTzIgQigqpHkFN0QlosQkezL2JAfd/1rmEI6zUHWg9RW2uMDxKqR+dCg26Nnx6DOCAjRPmCrAcUi8r6Hn9/Dadz9HRR+knpAPQ+Gz/R/H5aFblHcQOYNsHOctcaAyeK+JoBfqNkTSXexE6uuYgj7K6HLp0a+izDFl8AAqcdEa+mhkYcAGm925A4x8ZPAD9LQG3Y0l3BYbxHRqVWSlKp6kvayiQWjwzeGYTxZaM1xVuAbsFaEkvW7pf47//tQvscuipLraRYDoOyJ69UHmA7MeVO6fVLsQlOltNtlvzxpi+g4OE43T1/w/tkSQ2i8ngym5dxZfzGHDwpp4f/fz8feeS+iMPhBOQ+o6v6RO5lhk5S6Kw0dJkZ0BYxMCjgobk6ykAcfpKldtdfA+RJXd1mU/B9oATd/IoFBw0sBA63FWtnYxqyJ6QTffUeh5x1guBuWkKH/QkOes4IsOK59AuLcIS5CQlEMDqhUr3Yva4AaPmhacXQ+d48jUh8wUMWcuTnC8EzkQleNg+CYNEY3Odewrpb3qIJucbhhV8zZMAueLX9T2NmSwq3RqTS5EWoPEdYRknxIaOsKNjx17sZ+mRNew6cTRVJOXf7cNdanPZCtrcZC0fDzmjdbOxyQ856vxuIo6UbqsFIDBnDF/YEOdnNDQzgm7QRkLtE1BnZlmmf+Hequ7+nWWITF0LgB7gUEtEWOF7fBWeQq70nXtWIL/gMO/SZO70cMt0WGanpZJculQipcAf5HcErqYvyejZUJu6vq7P0Scgaf9ZIWGBmeGZKiNp9o5Z40KKS0L6rQe6ntb6pH/cu7x66MEmt6W38X9TSUWiUGkTIgBOFglKEDBkg/z8vI9ThKyrQDFc1vm2QDs4iFF40NJl1ti4L jTm02kLm qqkQBXnOwbJ1WVyLR3WZHDpv4fGyLPpq/EenKhz1aTncOZAux6a+2wiJr2AWV0x8w2Run5ZDqt8ngY2PcY+hYSUyoKiQcEsKiu96hFQxFxV5AJHOa4YsjTCGsmHikgFD+k7Qk1V1BPnpyRHtVU00Pr8oCAy0+1vLOsif/HgDiZ30LdDQBZcsnKNr51pKuJj2Qq4XbyxR2lL59AkOZdF8pScvNqlODwsEXHgTl8Vuj00oxMuw28gJHrH28sdN1srDvYYwGB+WVXyaiijpyBu3NLgwLPnri0slGOcvJ19+3GplaD33DGG0q9ZUQSrGGPonGNCRpIeG0qebAcIjyzWhuqQIFRuSyXfPlDwai4EIsQ2n3bLc= X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: On Fri, 11 Jul 2025, Baolin Wang wrote: > On 2025/7/11 06:20, Hugh Dickins wrote: > > On Thu, 10 Jul 2025, Baolin Wang wrote: > >> On 2025/7/9 15:57, Hugh Dickins wrote: > > ... > >>> > >>> The problem is with huge pages (or large folios) in shmem_writeout(): > >>> what goes in as a large folio may there have to be split into small > >>> pages; or it may be swapped out as one large folio, but fragmentation > >>> at swapin time demand that it be split into small pages when swapped in. > >> > >> Good point. > >> > >>> So, if there has been swapout since the large folio was modified beyond > >>> EOF, the folio that shmem_zero_eof() brings in does not guarantee what > >>> length needs to be zeroed. > >>> > >>> We could set that aside as a deficiency to be fixed later on: that > >>> would not be unreasonable, but I'm guessing that won't satisfy you. > >>> > >>> We could zero the maximum (the remainder of PMD size I believe) in > >>> shmem_zero_eof(): looping over small folios within the range, skipping > >>> !uptodate ones (but we do force them uptodate when swapping out, in > >>> order to keep the space reservation). TBH I've ignored that as a bad > >>> option, but it doesn't seem so bad to me now: ugly, but maybe not bad. > >> > >> However, IIUC, if the large folios are split in shmem_writeout(), and those > >> small folios which beyond EOF will be dropped and freed in > >> __split_unmapped_folio(), should we still consider them? > > > > You're absolutely right about the normal case, and thank you for making > > that point. Had I forgotten that when writing? Or was I already > > jumping ahead to the problem case? I don't recall, but was certainly > > wrong for not mentioning it. > > > > The abnormal case is when there's a "fallocend" beyond i_size (or beyond > > the small page extent spanning i_size) i.e. fallocate() has promised to > > keep pages allocated beyond EOF. In that case, __split_unmapped_folio() > > is keeping those pages. > > Ah, yes, you are right. > > > There could well be some optimization, involving fallocend, to avoid > > zeroing more than necessary; but I wouldn't want to say what in a hurry, > > it's quite confusing! > > Like you said, not only can a large folio split occur during swapout, but it > can also happen during a punch hole operation. Moreover, considering the > abnormal case of fallocate() you mentioned, we should find a more common > approach to mitigate the impact of fallocate(). > > For instance, when splitting, we could clear the 'uptodate' flag for these EOF > small folios that are beyond 'i_size' but less than the 'fallocend', so that > these EOF small folios will be re-initialized if they are used again. What do > you think? First impression: that's a great idea, much better than anything I was proposing. Let's hope I don't perceive some drawback overnight and renege. I don't love your patch below so much, we would probably want to gather the shmem_mapping() peculiarities together better (and seeing that repeated i_size_read(): IIRC 32-bit locking doesn't allow it in there). And there tends to be an assumption (don't ask me where) that a page once uptodate remains that way until it's freed: maybe no problem before it's inserted in the xarray (as you have), or maybe better before unfreezing, or maybe the page lock is already enough. Those my initial reactions. Hugh > > diff --git a/mm/huge_memory.c b/mm/huge_memory.c > index ce130225a8e5..2ccb442525d1 100644 > --- a/mm/huge_memory.c > +++ b/mm/huge_memory.c > @@ -3546,6 +3546,18 @@ static int __split_unmapped_folio(struct folio *folio, > int new_order, > lru_add_split_folio(origin_folio, release, lruvec, > list); > > + /* > + * fallocate() will keep folios allocated beyond EOF, > we should > + * clear the uptodate flag for these folios to re-zero > them > + * if necessary. > + */ > + if (shmem_mapping(mapping)) { > + loff_t i_size = i_size_read(mapping->host); > + > + if (i_size < end && release->index >= i_size) > + folio_clear_uptodate(release); > + } > + > /* Some pages can be beyond EOF: drop them from cache > */ > if (release->index >= end) { > if (shmem_mapping(mapping))