Received: by 2002:a05:6a10:6744:0:0:0:0 with SMTP id w4csp5780368pxu; Thu, 22 Oct 2020 10:50:01 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxtt+cZtS/Bu+HDWR6+KM0NS7o2zDgHWsyTe7W4Q2/eKCGgRTsPlVMKqRcYLQLT8OTNVWKQ X-Received: by 2002:a17:906:1b0d:: with SMTP id o13mr3363057ejg.526.1603389001238; Thu, 22 Oct 2020 10:50:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1603389001; cv=none; d=google.com; s=arc-20160816; b=FVtCRKI8i+AAke4Pkds8MrSOiHKW17veOlZIabUY+2WZ8s8XjQY2kgd+1tyUvFEkUT 5X4Jt8XQUj3P/m4wagUtHHn6LBuVnLN+ndn0OZPKeaaZVtfqYvOLJh60b6TcfIr0Rz3g ra0/w16a1o3/5QcM41t3T+LHOE+xORKXdr2/9H1/1g/Tg8d5exy8i7jJySRCrtOWHIoJ gVticyrpeQgiQR6HvRWlNrF6o6V/1UxnwikCpBUq+CJFxqdvIrlHiH6ZywAxyv6TTR+I oeZvDU0QqKtGF1AS8AYojiRd19x0fAdsrCaJuMWngKHb6fOG/JoyTt52coPiFTtPg4l1 FdgQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=ynt34DnzYzgFUcUwaxtdHXlhYDGKkh5KhjALkhgRhi0=; b=uetkxXNKTOPPngHfPPNMg8V6ofsyFQjfYnJUZt0QId3pYQgpsIx9LYjQETeU1s2wPv dLTETtmGsXdWp1DhC0lcm+XxHcEAmRLGv/gdYje3NTfciwZGmz/r+t7VsuPPipXAD51c 91DFf4E2BrwuWuXZE7VGxIigOcL4zkz5y8lOMUAbzV/HJUIkulAgSa6XwZmFv5Pzezk9 Tqw99t50pimx/+mExbBLcNqWy9ktU2Cjt/YVU7MrhV/fWXDCLHSyzck00E4sDrCmziF6 zp2kG2xR0Akg1bqSvSJjRWnd9DjH0vKeDiOoNnCV0PABUNMeKR3P3Tt0QCJxLYdOD+t7 YR2A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@aol.com header.s=a2048 header.b=fkGpkM3u; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=aol.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id dr8si1260149ejc.671.2020.10.22.10.49.39; Thu, 22 Oct 2020 10:50:01 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@aol.com header.s=a2048 header.b=fkGpkM3u; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=aol.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2508341AbgJVO54 (ORCPT + 99 others); Thu, 22 Oct 2020 10:57:56 -0400 Received: from sonic310-21.consmr.mail.gq1.yahoo.com ([98.137.69.147]:33944 "EHLO sonic310-21.consmr.mail.gq1.yahoo.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2508322AbgJVO54 (ORCPT ); Thu, 22 Oct 2020 10:57:56 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=aol.com; s=a2048; t=1603378674; bh=ynt34DnzYzgFUcUwaxtdHXlhYDGKkh5KhjALkhgRhi0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From:Subject; b=fkGpkM3uWG8FT8YmjI5CTs939186q9/AThkRbEu8UPdICYwYH+iNZDLel5IkhY+FcwV/XEIGmqTZ+yF/43Ic0LWzI0rsDsLnIMG1Id8WiQWqdvdFaRdpklPFer8XDQ16/c0k96rk7eqOnjXI1SyAo5BVqC2z8YUcX+30TPOFFnosFOwFQ7kL+z3yrtP53AaHORwRP1xBJiTzAJjXa/WZPtYhEp532zwq/9dbGI6wHSb1tba4qbkOTfjOafW9eMXdTnda3bY1jm985gmNiipzovHHlZXyO6x6hx9qbTrICy4u5kRtkQriUEUfLH9IRjtZ5Q9YWSP6pAkikemOE5pp5A== X-SONIC-DKIM-SIGN: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s2048; t=1603378674; bh=D7v7ses/EQlynD7/kpA1uqF06BkDM9/yEM46FAArVlV=; h=From:To:Subject:Date; b=f2spgBctehiibXnD6Fyz6WwTzn2qtpwJ/0SoFiVjgSAsGgZHaDD+DdKk1njoa7cTXX2WWhAktpTuess5wQVr067hKCtvfgCuyQDwyErxM1uzZpcusfBr9+/2FYS/OM0ZO9uPmJcYSmtsLLHAF/lcBhN6rcRU1+aPuxC4nvMByYsYsathGIO/Ks0PxyQvkVe5bJVXlbxve0JDpFB1jELZAB2OkXZS4YWJH5X9znjSaDoVlkGMeGUdhXs1EawfjqFqTkAgPsv0yrbbT+4zfZfCvl3vbZ4+bM2Bz6ZaoVElC1kR0OFACzf5trvAPYhAtQtbQntA7C9QXxcFOgLQ0WeVsA== X-YMail-OSG: XzsQs6AVM1kowrxiKNBE9p9.Y_CpExj2YnS0U5ekyCldx48VKB4kf3Cr8Bfb5pQ GUdz3YU.3p3nxi2sopmELoyhCTgce_dTbSwbFgRkl2NRlB.vob2lkLbfD6fH0weRTfoZrw_txN1K Uiqsj.SHrlwJ7yKz1fBekH67GO859mDZ8smqeLJMLNS.hOYhVQR0kZOxmT.re3hf56LEEdxv2W50 RzgQOaCoLi.MJLLzIc_ijGK5iNnIjSQPjJkl6UiVhLUXr1oSULD6Snw6VMr36m2KZAChq95KuOHx sNFO87opuU8eNDJUS2Um7kRNEGOo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M9HdHjRhW._TeYtatRJnHPHNiHr5P.n_ QOxQmp3rGQ7yhTWqyhod4jQdR84NJsI940b3XWXzk_6KbRR6cZGM2zlhntSMXYo4AaHviM4LQA09 P_JsPL87wRmKaBXULMVg2wAnFZeLLYb6QjfjvNAoE.GPNWNEUzO.36Qg83yiSJOYcyuWj6xiBld0 C5sU- Received: from sonic.gate.mail.ne1.yahoo.com by sonic310.consmr.mail.gq1.yahoo.com with HTTP; Thu, 22 Oct 2020 14:57:54 +0000 Received: by smtp401.mail.ir2.yahoo.com (VZM Hermes SMTP Server) with ESMTPA ID 354b2034a70b817070abfec37b60849b; Thu, 22 Oct 2020 14:57:50 +0000 (UTC) From: Gao Xiang To: linux-erofs@lists.ozlabs.org Cc: Chao Yu , Chao Yu , LKML , Gao Xiang Subject: [PATCH 2/4] erofs: get rid of magical Z_EROFS_MAPPING_STAGING Date: Thu, 22 Oct 2020 22:57:22 +0800 Message-Id: <20201022145724.27284-2-hsiangkao@aol.com> X-Mailer: git-send-email 2.24.0 In-Reply-To: <20201022145724.27284-1-hsiangkao@aol.com> References: <20201022145724.27284-1-hsiangkao@aol.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Length: 8924 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Gao Xiang Previously, we played around with magical page->mapping for short-lived temporary pages since we need to identify different types of pages in the same pcluster but both invalidated and short-lived temporary pages can have page->mapping == NULL. It was considered as safe because temporary pages are all non-LRU / non-movable pages. This patch tends to use specific page->private to identify short-lived pages instead so it won't rely on page->mapping anymore. Details are described in "compress.h" as well. Signed-off-by: Gao Xiang --- prelimitary test is done. will do stress test then. fs/erofs/compress.h | 50 ++++++++++++++++++++++++++++++----------- fs/erofs/decompressor.c | 2 +- fs/erofs/zdata.c | 42 +++++++++++++++++++++------------- fs/erofs/zdata.h | 1 + 4 files changed, 65 insertions(+), 30 deletions(-) diff --git a/fs/erofs/compress.h b/fs/erofs/compress.h index 3d452443c545..2bbf47f353ef 100644 --- a/fs/erofs/compress.h +++ b/fs/erofs/compress.h @@ -26,30 +26,54 @@ struct z_erofs_decompress_req { bool inplace_io, partial_decoding; }; +#define Z_EROFS_SHORTLIVED_PAGE (-1UL << 2) + /* - * - 0x5A110C8D ('sallocated', Z_EROFS_MAPPING_STAGING) - - * used to mark temporary allocated pages from other - * file/cached pages and NULL mapping pages. + * For all pages in a pcluster, page->private should be one of + * Type Last 2bits page->private + * short-lived page 00 Z_EROFS_SHORTLIVED_PAGE + * cached/managed page 00 pointer to z_erofs_pcluster + * online page (file-backed, 01/10/11 sub-index << 2 | count + * some pages can be used for inplace I/O) + * + * page->mapping should be one of + * Type page->mapping + * short-lived page NULL + * cached/managed page non-NULL or NULL (invalidated/truncated page) + * online page non-NULL + * + * For all managed pages, PG_private should be set with 1 extra refcount, + * which is used for page reclaim / migration. */ -#define Z_EROFS_MAPPING_STAGING ((void *)0x5A110C8D) -/* check if a page is marked as staging */ -static inline bool z_erofs_page_is_staging(struct page *page) +/* + * short-lived pages are pages directly from buddy system with specific + * page->private (no need to set PagePrivate since these are non-LRU / + * non-movable pages and bypass reclaim / migration code). + */ +static inline bool z_erofs_is_shortlived_page(struct page *page) { - return page->mapping == Z_EROFS_MAPPING_STAGING; + if (page->private != Z_EROFS_SHORTLIVED_PAGE) + return false; + + DBG_BUGON(page->mapping); + return true; } -static inline bool z_erofs_put_stagingpage(struct list_head *pagepool, - struct page *page) +static inline bool z_erofs_put_shortlivedpage(struct list_head *pagepool, + struct page *page) { - if (!z_erofs_page_is_staging(page)) + if (!z_erofs_is_shortlived_page(page)) return false; - /* staging pages should not be used by others at the same time */ - if (page_ref_count(page) > 1) + /* short-lived pages should not be used by others at the same time */ + if (page_ref_count(page) > 1) { put_page(page); - else + } else { + /* follow the pcluster rule above. */ + set_page_private(page, 0); list_add(&page->lru, pagepool); + } return true; } diff --git a/fs/erofs/decompressor.c b/fs/erofs/decompressor.c index cbadbf55c6c2..1cb1ffd10569 100644 --- a/fs/erofs/decompressor.c +++ b/fs/erofs/decompressor.c @@ -76,7 +76,7 @@ static int z_erofs_lz4_prepare_destpages(struct z_erofs_decompress_req *rq, victim = erofs_allocpage(pagepool, GFP_KERNEL); if (!victim) return -ENOMEM; - victim->mapping = Z_EROFS_MAPPING_STAGING; + set_page_private(victim, Z_EROFS_SHORTLIVED_PAGE); } rq->out[i] = victim; } diff --git a/fs/erofs/zdata.c b/fs/erofs/zdata.c index 86fd3bf62af6..afeadf413c2c 100644 --- a/fs/erofs/zdata.c +++ b/fs/erofs/zdata.c @@ -255,6 +255,7 @@ int erofs_try_to_free_cached_page(struct address_space *mapping, erofs_workgroup_unfreeze(&pcl->obj, 1); if (ret) { + set_page_private(page, 0); ClearPagePrivate(page); put_page(page); } @@ -648,12 +649,12 @@ static int z_erofs_do_read_page(struct z_erofs_decompress_frontend *fe, retry: err = z_erofs_attach_page(clt, page, page_type); - /* should allocate an additional staging page for pagevec */ + /* should allocate an additional short-lived page for pagevec */ if (err == -EAGAIN) { struct page *const newpage = alloc_page(GFP_NOFS | __GFP_NOFAIL); - newpage->mapping = Z_EROFS_MAPPING_STAGING; + set_page_private(newpage, Z_EROFS_SHORTLIVED_PAGE); err = z_erofs_attach_page(clt, newpage, Z_EROFS_PAGE_TYPE_EXCLUSIVE); if (!err) @@ -710,6 +711,11 @@ static void z_erofs_decompress_kickoff(struct z_erofs_decompressqueue *io, queue_work(z_erofs_workqueue, &io->u.work); } +static bool z_erofs_page_is_invalidated(struct page *page) +{ + return !page->mapping && !z_erofs_is_shortlived_page(page); +} + static void z_erofs_decompressqueue_endio(struct bio *bio) { tagptr1_t t = tagptr_init(tagptr1_t, bio->bi_private); @@ -722,7 +728,7 @@ static void z_erofs_decompressqueue_endio(struct bio *bio) struct page *page = bvec->bv_page; DBG_BUGON(PageUptodate(page)); - DBG_BUGON(!page->mapping); + DBG_BUGON(z_erofs_page_is_invalidated(page)); if (err) SetPageError(page); @@ -795,9 +801,9 @@ static int z_erofs_decompress_pcluster(struct super_block *sb, /* all pages in pagevec ought to be valid */ DBG_BUGON(!page); - DBG_BUGON(!page->mapping); + DBG_BUGON(z_erofs_page_is_invalidated(page)); - if (z_erofs_put_stagingpage(pagepool, page)) + if (z_erofs_put_shortlivedpage(pagepool, page)) continue; if (page_type == Z_EROFS_VLE_PAGE_TYPE_HEAD) @@ -831,9 +837,9 @@ static int z_erofs_decompress_pcluster(struct super_block *sb, /* all compressed pages ought to be valid */ DBG_BUGON(!page); - DBG_BUGON(!page->mapping); + DBG_BUGON(z_erofs_page_is_invalidated(page)); - if (!z_erofs_page_is_staging(page)) { + if (!z_erofs_is_shortlived_page(page)) { if (erofs_page_is_managed(sbi, page)) { if (!PageUptodate(page)) err = -EIO; @@ -858,7 +864,7 @@ static int z_erofs_decompress_pcluster(struct super_block *sb, overlapped = true; } - /* PG_error needs checking for inplaced and staging pages */ + /* PG_error needs checking for all non-managed pages */ if (PageError(page)) { DBG_BUGON(PageUptodate(page)); err = -EIO; @@ -897,8 +903,8 @@ static int z_erofs_decompress_pcluster(struct super_block *sb, if (erofs_page_is_managed(sbi, page)) continue; - /* recycle all individual staging pages */ - (void)z_erofs_put_stagingpage(pagepool, page); + /* recycle all individual short-lived pages */ + (void)z_erofs_put_shortlivedpage(pagepool, page); WRITE_ONCE(compressed_pages[i], NULL); } @@ -908,10 +914,10 @@ static int z_erofs_decompress_pcluster(struct super_block *sb, if (!page) continue; - DBG_BUGON(!page->mapping); + DBG_BUGON(z_erofs_page_is_invalidated(page)); - /* recycle all individual staging pages */ - if (z_erofs_put_stagingpage(pagepool, page)) + /* recycle all individual short-lived pages */ + if (z_erofs_put_shortlivedpage(pagepool, page)) continue; if (err < 0) @@ -1011,13 +1017,17 @@ static struct page *pickup_page_for_submission(struct z_erofs_pcluster *pcl, mapping = READ_ONCE(page->mapping); /* - * unmanaged (file) pages are all locked solidly, + * file-backed online pages in plcuster are all locked steady, * therefore it is impossible for `mapping' to be NULL. */ if (mapping && mapping != mc) /* ought to be unmanaged pages */ goto out; + /* directly return for shortlived page as well */ + if (z_erofs_is_shortlived_page(page)) + goto out; + lock_page(page); /* only true if page reclaim goes wrong, should never happen */ @@ -1062,8 +1072,8 @@ static struct page *pickup_page_for_submission(struct z_erofs_pcluster *pcl, out_allocpage: page = erofs_allocpage(pagepool, gfp | __GFP_NOFAIL); if (!tocache || add_to_page_cache_lru(page, mc, index + nr, gfp)) { - /* non-LRU / non-movable temporary page is needed */ - page->mapping = Z_EROFS_MAPPING_STAGING; + /* turn into temporary page if fails */ + set_page_private(page, Z_EROFS_SHORTLIVED_PAGE); tocache = false; } diff --git a/fs/erofs/zdata.h b/fs/erofs/zdata.h index 68c9b29fc0ca..b503b353d4ab 100644 --- a/fs/erofs/zdata.h +++ b/fs/erofs/zdata.h @@ -173,6 +173,7 @@ static inline void z_erofs_onlinepage_endio(struct page *page) v = atomic_dec_return(u.o); if (!(v & Z_EROFS_ONLINEPAGE_COUNT_MASK)) { + set_page_private(page, 0); ClearPagePrivate(page); if (!PageError(page)) SetPageUptodate(page); -- 2.24.0