Received: by 2002:a25:e7d8:0:0:0:0:0 with SMTP id e207csp127804ybh; Mon, 9 Mar 2020 17:50:05 -0700 (PDT) X-Google-Smtp-Source: ADFU+vt6y31pmesky0NHWwQwkLSziTIVbSd03flJLr+Yb2mEO9ACTn5XyaRS6e/fH7IO7+jbA+QC X-Received: by 2002:a9d:7756:: with SMTP id t22mr14400845otl.272.1583801405335; Mon, 09 Mar 2020 17:50:05 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1583801405; cv=none; d=google.com; s=arc-20160816; b=MqWSv8KAqzCIjn7WO0w9fQ3h5MGPgGYw/fioqm9O4ZiWsmxekCmbsIZqVOhtpTyENi pjnaktOmljP5LYC91iW/gKMiJkW7F/1Eai9ZvvwXcCIrJ8mOitV2MxuTxbgqX6sQjX4s 1tE/qF3YzNDqQbUVhjBYPUdSSNa2E4rsxFlxMa3Au81g3V8pPlBQJgG4Ki+oovTGneF8 vKWxSvbTmqtDXtBVV1tmRALmf7yJJzvrXuU87ipK963/Rfkx2cegXDOoejsYRh7NmgA4 3q9n0fADIdi0UmqFOjNXMzUsZnjFfIPWcUIqba2FcyRseZaqvudUotVIa7Z1X7FQ/YuJ Gk0w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:subject:cc:to:from:date :dkim-signature; bh=wLxk+f5/djqx2lwAvBctUv3G6TuArZhTsv+CiozImu8=; b=dJEW0+o1QlyFX6Snprh+SRzezIJ8DMyB0FV+yne70HFNkVQzucvxf73SO40SSML0bQ i+jWLmnKfb6jMbZJLM343nnkdqnwzacJSd70mKUaGi8CGIYApfv42cRC2wTyglsk/7Uw Yvb1K/0Uex5YCzyY71Fsh90DQDCfeRTf8hJozxGQJuo/QUTUxuw11pLfy/gSygeuRwMX PlA+pcxlYe+NMRdqzsoT5fesDei4R1HZxLs4ZPWDnyTHGcPNE8LhC+OCsuFphVmvu3gN I6ThaYLx24CRKyCTydyss/P2JKUsXe9gqUNbxDXyvMfOxY14Y4BZmy+nS+C9R0u6hShf bA1w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=m2SM3CNe; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id u125si1650780oie.52.2020.03.09.17.49.53; Mon, 09 Mar 2020 17:50:05 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=m2SM3CNe; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727577AbgCJAs4 (ORCPT + 99 others); Mon, 9 Mar 2020 20:48:56 -0400 Received: from mail.kernel.org ([198.145.29.99]:47178 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727287AbgCJAsz (ORCPT ); Mon, 9 Mar 2020 20:48:55 -0400 Received: from localhost.localdomain (c-73-231-172-41.hsd1.ca.comcast.net [73.231.172.41]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 21F192146E; Tue, 10 Mar 2020 00:48:55 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1583801335; bh=MyWY5amDJAzJzdzhFcv6Tu9m3xmj/uJuETu5vTpbu1E=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=m2SM3CNeB9AYYwMegS2jCzUUGfrXy4qy+7yHmzpz470bfnGsfowU9w1uN04i1PjNS NPr39yPhzzG/w7UlNxW5oRW4PH5Ukm7/+fUWgOqN8Rk6XTj+mzCpMcXBWHGnfsyjvT JWHDqz5vyedqi0m4W3YIlVS5G458CGUYD97ld12Y= Date: Mon, 9 Mar 2020 17:48:54 -0700 From: Andrew Morton To: Wei Yang Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org, Tim Chen Subject: Re: [PATCH] mm/swap_slots.c: don't reset the cache slot after use Message-Id: <20200309174854.b6b8c7f019c3dde048c28f94@linux-foundation.org> In-Reply-To: <20200309090940.34130-1-richard.weiyang@linux.alibaba.com> References: <20200309090940.34130-1-richard.weiyang@linux.alibaba.com> X-Mailer: Sylpheed 3.5.1 (GTK+ 2.24.31; x86_64-pc-linux-gnu) Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, 9 Mar 2020 17:09:40 +0800 Wei Yang wrote: > Currently we would clear the cache slot if it is used. While this is not > necessary, since this entry would not be used until refilled. > > Leave it untouched and assigned the value directly to entry which makes > the code little more neat. > > Also this patch merges the else and if, since this is the only case we > refill and repeat swap cache. cc Tim, who can hopefully remember how this code works ;) > --- a/mm/swap_slots.c > +++ b/mm/swap_slots.c > @@ -309,7 +309,7 @@ int free_swap_slot(swp_entry_t entry) > > swp_entry_t get_swap_page(struct page *page) > { > - swp_entry_t entry, *pentry; > + swp_entry_t entry; > struct swap_slots_cache *cache; > > entry.val = 0; > @@ -336,13 +336,10 @@ swp_entry_t get_swap_page(struct page *page) > if (cache->slots) { > repeat: > if (cache->nr) { > - pentry = &cache->slots[cache->cur++]; > - entry = *pentry; > - pentry->val = 0; > + entry = cache->slots[cache->cur++]; > cache->nr--; > - } else { > - if (refill_swap_slots_cache(cache)) > - goto repeat; > + } else if (refill_swap_slots_cache(cache)) { > + goto repeat; > } > } > mutex_unlock(&cache->alloc_lock); > -- > 2.20.1 (Apple Git-117)