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 X-Spam-Level: X-Spam-Status: No, score=-0.5 required=3.0 tests=DKIM_INVALID,DKIM_SIGNED, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS, URIBL_BLOCKED autolearn=no autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 9784FC433DF for ; Wed, 17 Jun 2020 12:17:24 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 28D6520786 for ; Wed, 17 Jun 2020 12:17:23 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b="P5WYbDs+" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 28D6520786 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=infradead.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 5BCA86B000E; Wed, 17 Jun 2020 08:17:23 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 56DE06B0010; Wed, 17 Jun 2020 08:17:23 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 482BB6B0022; Wed, 17 Jun 2020 08:17:23 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0216.hostedemail.com [216.40.44.216]) by kanga.kvack.org (Postfix) with ESMTP id 2FC966B000E for ; Wed, 17 Jun 2020 08:17:23 -0400 (EDT) Received: from smtpin22.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay03.hostedemail.com (Postfix) with ESMTP id 948B98248068 for ; Wed, 17 Jun 2020 12:17:22 +0000 (UTC) X-FDA: 76938603924.22.men67_1a0ce7426e07 Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin22.hostedemail.com (Postfix) with ESMTP id 50B2F18038E92 for ; Wed, 17 Jun 2020 12:17:22 +0000 (UTC) X-HE-Tag: men67_1a0ce7426e07 X-Filterd-Recvd-Size: 4356 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) by imf08.hostedemail.com (Postfix) with ESMTP for ; Wed, 17 Jun 2020 12:17:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20170209; h=In-Reply-To:Content-Type:MIME-Version :References:Message-ID:Subject:Cc:To:From:Date:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description; bh=RldClxLNf1hmXc0hhlCmSSdwgcV44W4PDkE7rUAE2fU=; b=P5WYbDs+GCsATNmQJKc2bzaDoc vlrWZEbh0/JIdsel1YSi5xhiIkrItaHY70ygHRr3kh8KIgqhHmZInZ3wctEf5ElFP+LvNgwWn0qfy zgf1jydSLWjaMr2VYXBznVgLV1dIr0W7XEFeplCTKg29iYC7WHmgL1LzsxXVR/X2tqjF4/mwr2yJ6 PoE/hZdDdMRocr9zLZAOTNVC5SLcwBBv9WqXiRtO1lUFTcIX0B5KZSuY1UoBaoFB+Kyuh5rQROXnL V7pdNw1fs9pFegg1qzapS0Q9N7qpunCdBsO9PPsFpzdv+5+n1Qa/ZcmSXz/WJ8bJTWS1Vvx03i64W FScdij6w==; Received: from willy by bombadil.infradead.org with local (Exim 4.92.3 #3 (Red Hat Linux)) id 1jlX0H-0002nH-8L; Wed, 17 Jun 2020 12:17:17 +0000 Date: Wed, 17 Jun 2020 05:17:17 -0700 From: Matthew Wilcox To: js1304@gmail.com Cc: Andrew Morton , linux-mm@kvack.org, linux-kernel@vger.kernel.org, Johannes Weiner , Michal Hocko , Hugh Dickins , Minchan Kim , Vlastimil Babka , Mel Gorman , kernel-team@lge.com, Joonsoo Kim Subject: Re: [PATCH v6 4/6] mm/swapcache: support to handle the exceptional entries in swapcache Message-ID: <20200617121717.GI8681@bombadil.infradead.org> References: <1592371583-30672-1-git-send-email-iamjoonsoo.kim@lge.com> <1592371583-30672-5-git-send-email-iamjoonsoo.kim@lge.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1592371583-30672-5-git-send-email-iamjoonsoo.kim@lge.com> X-Rspamd-Queue-Id: 50B2F18038E92 X-Spamd-Result: default: False [0.00 / 100.00] X-Rspamd-Server: rspam04 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: On Wed, Jun 17, 2020 at 02:26:21PM +0900, js1304@gmail.com wrote: > From: Joonsoo Kim > > Swapcache doesn't handle the exceptional entries since there is no case Don't call them exceptional entries. The radix tree has/had the concecpt of exceptional entries. The swapcache doesn't use the radix tree any more, it uses the XArray. The XArray has value entries. But you shouldn't call them value entries either; that's an XArray concept. The swap cache and indeed page cache use value entries to implement shadow entries (they're also used to implement dax entries and swap entries in the page cache). So just call them shadow entries here. I know there are still places which use the term 'nrexceptional' in the kernel. I just haven't got round to replacing them yet. Please don't add more. > +void clear_shadow_from_swap_cache(int type, unsigned long begin, > + unsigned long end) > +{ > + unsigned long curr; > + void *old; > + swp_entry_t entry = swp_entry(type, begin); > + struct address_space *address_space = swap_address_space(entry); > + XA_STATE(xas, &address_space->i_pages, begin); > + > +retry: > + xa_lock_irq(&address_space->i_pages); > + for (curr = begin; curr <= end; curr++) { > + entry = swp_entry(type, curr); > + if (swap_address_space(entry) != address_space) { > + xa_unlock_irq(&address_space->i_pages); > + address_space = swap_address_space(entry); > + begin = curr; > + xas_set(&xas, begin); > + goto retry; > + } > + > + old = xas_load(&xas); > + if (!xa_is_value(old)) > + continue; > + xas_store(&xas, NULL); > + address_space->nrexceptional--; > + xas_next(&xas); > + } > + xa_unlock_irq(&address_space->i_pages); > +} This is a very clunky loop. I'm not sure it's even right, given that you change address space without changing the xas's address space. How about this? for (;;) { XA_STATE(xas, &address_space->i_pages, begin); unsigned long nr_shadows = 0; xas_lock_irq(&xas); xas_for_each(&xas, entry, end) { if (!xa_is_value(entry)) continue; xas_store(&xas, NULL); nr_shadows++; } address_space->nr_exceptionals -= nr_shadows; xas_unlock_irq(&xas); if (xas.xa_index >= end) break; entry = swp_entry(type, xas.xa_index); address_space = swap_address_space(entry); }