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 A2CAAC3DA61 for ; Mon, 29 Jul 2024 12:49:22 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 1E60F6B009D; Mon, 29 Jul 2024 08:49:22 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 16EE66B009E; Mon, 29 Jul 2024 08:49:22 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 00E766B00A2; Mon, 29 Jul 2024 08:49:21 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id D3A2F6B009D for ; Mon, 29 Jul 2024 08:49:21 -0400 (EDT) Received: from smtpin18.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id 48940C034D for ; Mon, 29 Jul 2024 12:49:21 +0000 (UTC) X-FDA: 82392770922.18.8FD44F9 Received: from casper.infradead.org (casper.infradead.org [90.155.50.34]) by imf06.hostedemail.com (Postfix) with ESMTP id 1779518000C for ; Mon, 29 Jul 2024 12:49:18 +0000 (UTC) Authentication-Results: imf06.hostedemail.com; dkim=pass header.d=infradead.org header.s=casper.20170209 header.b=lUc196LX; spf=none (imf06.hostedemail.com: domain of willy@infradead.org has no SPF policy when checking 90.155.50.34) smtp.mailfrom=willy@infradead.org; dmarc=none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1722257333; 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:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=CUzNSkVbhIag+ard2YVZr+G/AEzI8BDb93+haUOAT98=; b=f/cF3/8DBb9eIXO1xkCseoYUwqvLNEggcPTh1EyTEl+Xo51/7E7U/nWbpFgg+Y3Qf2LEmc UjCDwgflJ7uMQTZ+ovXJcAHA/VedGeF9RQ4pXxhfxZJl0Njv3mNCSxXrV4Ov/VmhklRYlo FNJaTbT15uziXjEwmDmfNzC4myQbA6c= ARC-Authentication-Results: i=1; imf06.hostedemail.com; dkim=pass header.d=infradead.org header.s=casper.20170209 header.b=lUc196LX; spf=none (imf06.hostedemail.com: domain of willy@infradead.org has no SPF policy when checking 90.155.50.34) smtp.mailfrom=willy@infradead.org; dmarc=none ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1722257333; a=rsa-sha256; cv=none; b=AE+Wp9Sr8eHENbJ5hUc0YYMxOz3aOyKD6pdW1Mwz+aUK3W7/Iou4u/8GaJuU/sEHcN+rer XxAqdhw1Z36ePBeQbRN3VNb4KTPMBECSGDf6B4WQzVHZFZCxBgDy5/A79a8mhuuzr6qEcg YgQVZDJRKli9wbTYZpYCW6pZgowp4PA= DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=In-Reply-To:Content-Transfer-Encoding: Content-Type:MIME-Version:References:Message-ID:Subject:Cc:To:From:Date: Sender:Reply-To:Content-ID:Content-Description; bh=CUzNSkVbhIag+ard2YVZr+G/AEzI8BDb93+haUOAT98=; b=lUc196LXunlWJ4AfCO67OE6fV7 vf7RXnhgZgRE7fvZd2UMv6CZJl8ENONI4uSfWeh6iTFZtz/97IhMtY2qBM/+309g6m0Xw4dHuGk6z FMTivIWUyTdj3YfxR6WNhRodxpJqtmekVz4TXovyT/j30VFBWZfQ0u9I4iEs1xsp5jiEHqao9li5L RvxqIMT9xPIXofLq3vejO2ztPFj7Cp1HKdHjaVUj394COCBAZkCYrwuENhgFtjDRpF4QLxrbXzn1x kyCJYD6TzXR8nzh70Et0lDHMOP8wRdDG/dEIX6wi+G8leSjE/77Zi3z3WRvUnX4417vO7ETBdwNMg aedL0Ryg==; Received: from willy by casper.infradead.org with local (Exim 4.97.1 #2 (Red Hat Linux)) id 1sYPoI-0000000DZYp-1mMx; Mon, 29 Jul 2024 12:49:06 +0000 Date: Mon, 29 Jul 2024 13:49:06 +0100 From: Matthew Wilcox To: Barry Song <21cnbao@gmail.com> Cc: akpm@linux-foundation.org, linux-mm@kvack.org, ying.huang@intel.com, baolin.wang@linux.alibaba.com, chrisl@kernel.org, david@redhat.com, hannes@cmpxchg.org, hughd@google.com, kaleshsingh@google.com, kasong@tencent.com, linux-kernel@vger.kernel.org, mhocko@suse.com, minchan@kernel.org, nphamcs@gmail.com, ryan.roberts@arm.com, senozhatsky@chromium.org, shakeel.butt@linux.dev, shy828301@gmail.com, surenb@google.com, v-songbaohua@oppo.com, xiang@kernel.org, yosryahmed@google.com, Chuanhua Han Subject: Re: [PATCH v5 3/4] mm: support large folios swapin as a whole for zRAM-like swapfile Message-ID: References: <20240726094618.401593-1-21cnbao@gmail.com> <20240726094618.401593-4-21cnbao@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: X-Rspamd-Server: rspam03 X-Rspam-User: X-Rspamd-Queue-Id: 1779518000C X-Stat-Signature: megqj8ijxa7bpbf1i3fur99sghama6t9 X-HE-Tag: 1722257358-283137 X-HE-Meta: U2FsdGVkX18cxppCndBbzRoTu6rtUrjCvh4hLkO+5TF1eeksYAMQoTXMJUUAr7Y6BZzyj44zuKQnkJFKPjCZxTv2viK+Xmln8+gIsw+ejlYXCTsPVBvoY2KWmAebt77Y/Ap2sdVYmDDH2SdtlIH/sR3OuyBM1UaMd7pfEJDlLw7Zke5Ru8hGMbhFy5CqRb/qTBVMlM3ZCQBvrabQt21SUVmH0mWx2S9nkFoRwfuXwJMmR0ZuQ62n5vkAcbfF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ogofilter, 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 Mon, Jul 29, 2024 at 04:46:42PM +1200, Barry Song wrote: > On Mon, Jul 29, 2024 at 4:41 PM Barry Song <21cnbao@gmail.com> wrote: > > > > On Mon, Jul 29, 2024 at 3:51 PM Matthew Wilcox wrote: > > > > > > On Fri, Jul 26, 2024 at 09:46:17PM +1200, Barry Song wrote: > > > > - folio = vma_alloc_folio(GFP_HIGHUSER_MOVABLE, 0, > > > > - vma, vmf->address, false); > > > > + folio = alloc_swap_folio(vmf); > > > > page = &folio->page; > > > > > > This is no longer correct. You need to set 'page' to the precise page > > > that is being faulted rather than the first page of the folio. It was > > > fine before because it always allocated a single-page folio, but now it > > > must use folio_page() or folio_file_page() (whichever has the correct > > > semantics for you). > > > > > > Also you need to fix your test suite to notice this bug. I suggest > > > doing that first so that you know whether you've got the calculation > > > correct. > > > > I don't understand why the code is designed in the way the page > > is the first page of this folio. Otherwise, we need lots of changes > > later while mapping the folio in ptes and rmap. What? folio = swap_cache_get_folio(entry, vma, vmf->address); if (folio) page = folio_file_page(folio, swp_offset(entry)); page is the precise page, not the first page of the folio. > For both accessing large folios in the swapcache and allocating > new large folios, the page points to the first page of the folio. we > are mapping the whole folio not the specific page. But what address are we mapping the whole folio at? > for swapcache cases, you can find the same thing here, > > if (folio_test_large(folio) && folio_test_swapcache(folio)) { > ... > entry = folio->swap; > page = &folio->page; > } Yes, but you missed some important lines from your quote: page_idx = idx; address = folio_start; ptep = folio_ptep; nr_pages = nr; We deliberate adjust the address so that, yes, we're mapping the entire folio, but we're mapping it at an address that means that the page we actually faulted on ends up at the address that we faulted on.