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=-3.8 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, NICE_REPLY_A,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 663A8C388F7 for ; Mon, 26 Oct 2020 00:14:15 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id CDBEC223EA for ; Mon, 26 Oct 2020 00:14:14 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=kernel.org header.i=@kernel.org header.b="CVWf6PdO" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org CDBEC223EA Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=linux-foundation.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 17B976B005D; Sun, 25 Oct 2020 20:14:14 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 12C4E6B0062; Sun, 25 Oct 2020 20:14:14 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 041656B0068; Sun, 25 Oct 2020 20:14:13 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0146.hostedemail.com [216.40.44.146]) by kanga.kvack.org (Postfix) with ESMTP id C90446B005D for ; Sun, 25 Oct 2020 20:14:13 -0400 (EDT) Received: from smtpin22.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay02.hostedemail.com (Postfix) with ESMTP id 64CD83625 for ; Mon, 26 Oct 2020 00:14:13 +0000 (UTC) X-FDA: 77412154386.22.bee67_2003e332726f Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin22.hostedemail.com (Postfix) with ESMTP id 4961218038E67 for ; Mon, 26 Oct 2020 00:14:13 +0000 (UTC) X-HE-Tag: bee67_2003e332726f X-Filterd-Recvd-Size: 2792 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by imf05.hostedemail.com (Postfix) with ESMTP for ; Mon, 26 Oct 2020 00:14:12 +0000 (UTC) Received: from X1 (nat-ab2241.sltdut.senawave.net [162.218.216.4]) (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 C1637223BE; Mon, 26 Oct 2020 00:14:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1603671251; bh=+XvynSj/JRwnS3CMFpuxWWK3dpmsjzmgNq1XtjZG5ls=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=CVWf6PdOOaPZewJwUn4D2IdorViwmdjaXXRbM595VwSxU/GcAxuG5EynebUKWtDMu m81uokGUUg7SYkBT4bXKrWCXmvcNARvNcYbhEpkXdujZgL0nBxK9PHmmXesz8/2ixA ylGeyMgs5zPvAkXCq2DJL+VjrGIBuGtHlL7qnw3Y= Date: Sun, 25 Oct 2020 17:14:11 -0700 From: Andrew Morton To: Miaohe Lin Cc: , , Hugh Dickins Subject: Re: [PATCH] mm: swap: Use memset to fill the swap_map with SWAP_HAS_CACHE Message-Id: <20201025171411.20fce472df99bc43fce7156c@linux-foundation.org> In-Reply-To: <20200921122224.7139-1-linmiaohe@huawei.com> References: <20200921122224.7139-1-linmiaohe@huawei.com> X-Mailer: Sylpheed 3.5.1 (GTK+ 2.24.32; x86_64-pc-linux-gnu) Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit 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 Mon, 21 Sep 2020 08:22:24 -0400 Miaohe Lin wrote: > We could use helper memset to fill the swap_map with SWAP_HAS_CACHE instead > of a direct loop here to simplify the code. Also we can remove the local > variable i and map this way. > > ... > > --- a/mm/swapfile.c > +++ b/mm/swapfile.c > @@ -975,8 +975,7 @@ static int swap_alloc_cluster(struct swap_info_struct *si, swp_entry_t *slot) > { > unsigned long idx; > struct swap_cluster_info *ci; > - unsigned long offset, i; > - unsigned char *map; > + unsigned long offset; > > /* > * Should not even be attempting cluster allocations when huge > @@ -996,9 +995,7 @@ static int swap_alloc_cluster(struct swap_info_struct *si, swp_entry_t *slot) > alloc_cluster(si, idx); > cluster_set_count_flag(ci, SWAPFILE_CLUSTER, CLUSTER_FLAG_HUGE); > > - map = si->swap_map + offset; > - for (i = 0; i < SWAPFILE_CLUSTER; i++) > - map[i] = SWAP_HAS_CACHE; > + memset(si->swap_map + offset, SWAP_HAS_CACHE, SWAPFILE_CLUSTER); > unlock_cluster(ci); > swap_range_alloc(si, offset, SWAPFILE_CLUSTER); > *slot = swp_entry(si->type, offset); I suppose so. But it does assume that the ->swapmap array has the type char. If we ever change that, breakage will ensue.