Received: by 2002:a05:6a10:1287:0:0:0:0 with SMTP id d7csp1629201pxv; Fri, 16 Jul 2021 13:51:37 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwfMjTZEZh+2RWJslWw9fBTOonZ/lvVxUUpbfMjUJIMiO7M7i3JuCtlgp/QBAD4XP3GAWIc X-Received: by 2002:a5e:970a:: with SMTP id w10mr8484099ioj.46.1626468697104; Fri, 16 Jul 2021 13:51:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1626468697; cv=none; d=google.com; s=arc-20160816; b=WeZmSYuvCJ/O4hZd86sodHVEs3tL+MCWpdPxllckZqNV2HT/I7MF5pWkFwdy/+mRFH UJj2qwfBv9cs8qRliMQ9Oi4RXMcrmf6k626EGXyewUBNEyZwFA2T39NB35A0Pv/YgKzf 9tqWDN6tRY7ONP34mfzGqfSVVBO8MI8AokoxggsbG/ooYOmluYggU1mcDjmXlOv0EdQ8 oOv77nFIDpxZYFgwnFSwcIGCeI+SWjEWESqYc6YuANq2m/0/zwDPBXfyXZYhOgbLXqZk rZ27Fa8KuhvDnXXgeLdAY3hhlV4t7TS2FtXb2LEFn3OMePq7SVzDq/8dZiuFaX37tARe 356Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:references:message-id:in-reply-to :subject:cc:to:from:date:dkim-signature; bh=eP+vdjS8P2oSI7HEDS+oh3O0Y+BLb63u8Xg1Z86gM8g=; b=MBmQvbNwEwyfIao2xs+K8FAGUB0KjTsHptW7POcYd1pZWQFr3BRLD+dqp+mJ7yhzpD zHWTC4S2V8CDTar3OUNla4ZIhVUrmlp7Hoa0pz1v2pHECVVhn14MfzcEUbzk/SRiGVdC eBpEXAC2RKN3osI0QPC4wXEyfYc4v+SkDRt0m24caTLguCNXbBiwvabkZuo7B9I5D0P0 JjT8WUdKPthi5qgNyaNJ+vy1pa8TXossltN2rNe8mKP/1CCODqkL7P5qScb1fSsN+Q1I q6gPY1lcdr9YTV/TCJIdCUfk41fO0+maDEoZAg0yYRXS8drDVT5Q8CAa3ItuCP7OSwGY /Slg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=OyZEvDSz; 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=google.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id t11si11774454ils.106.2021.07.16.13.51.23; Fri, 16 Jul 2021 13:51:37 -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=@google.com header.s=20161025 header.b=OyZEvDSz; 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=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232957AbhGPUxO (ORCPT + 99 others); Fri, 16 Jul 2021 16:53:14 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44324 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230415AbhGPUxK (ORCPT ); Fri, 16 Jul 2021 16:53:10 -0400 Received: from mail-qv1-xf2d.google.com (mail-qv1-xf2d.google.com [IPv6:2607:f8b0:4864:20::f2d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B7EC8C06175F for ; Fri, 16 Jul 2021 13:50:13 -0700 (PDT) Received: by mail-qv1-xf2d.google.com with SMTP id ck17so5224960qvb.9 for ; Fri, 16 Jul 2021 13:50:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=date:from:to:cc:subject:in-reply-to:message-id:references :mime-version; bh=eP+vdjS8P2oSI7HEDS+oh3O0Y+BLb63u8Xg1Z86gM8g=; b=OyZEvDSzk2JzXO1WlOoiW9zJM0/OC3IPYXIxFo7A1ItTKDB7ZkYWs6Z0LNEDzV0wP7 an2p0lafJ7R9/5GOEoUxx5Wv0KlatzZ9CYV3rmS+L/a/zpw1jlBEggj25yOGpnVt0+oh EvepArkPWyoYKLYU+SlIEbaEji7vbAdaUXBCLxfQyr0487znAEYX9qEmGTmYQz/UqSJr LOAgxeypTy0xCyTrlf6kvHmbzA4hMxzYGl6WmAlFO0Oeiwq98cSF6VBK3Un4xq0mq6M1 LCY57MDqkIqbLVf1IieX34spfe6AD4tfqsIO3oafpmk3Uq/qh78j7mSFT5yKpyORO8Mi u02A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:in-reply-to:message-id :references:mime-version; bh=eP+vdjS8P2oSI7HEDS+oh3O0Y+BLb63u8Xg1Z86gM8g=; b=onAB/V62tVpOxgPCdmKOCxbHuneEw5faZafHrP0weHUIfXGOHHLJAsbaJMh7JLOyzh zr8yr3QuMlGc9td9WELMPqstdk3q/Cn2RDog71YyW5Z7EG+QlquSIlmCB9sCwSvlk9vs qjNgq/DLk9p0KNTC0Qx3SDml4hnSw6N8YtadOT96Lp/8tLbUM+VKltTkYr8K27LNdv25 cFLNNeA5IpDpNztShDUnbc4IBRjsRUDXPN0fzLxEdIOsDAEAyWb4jIi8osT+j1s9R9Rs zQP9HlyPTBQeSgqSSld9tx69h/ab7gLEI8YZJ1LuB6Fn5++7kTPAss8xj5/Ezu68OhRY hMkQ== X-Gm-Message-State: AOAM532IMVI2ZRySFD+saewpwlWlJP6zk+8PYVLP9lCgX9RVEc+XW5ex wWAhWH75pUwa2zVDnJnTNxiSLA== X-Received: by 2002:a0c:d845:: with SMTP id i5mr12130743qvj.32.1626468612726; Fri, 16 Jul 2021 13:50:12 -0700 (PDT) Received: from ripple.attlocal.net (172-10-233-147.lightspeed.sntcca.sbcglobal.net. [172.10.233.147]) by smtp.gmail.com with ESMTPSA id c16sm3591087qtv.32.2021.07.16.13.50.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 16 Jul 2021 13:50:12 -0700 (PDT) Date: Fri, 16 Jul 2021 13:50:10 -0700 (PDT) From: Hugh Dickins X-X-Sender: hugh@ripple.anvils To: Zhansaya Bagdauletkyzy cc: akpm@linux-foundation.org, tyhicks@linux.microsoft.com, pasha.tatashin@soleen.com, willy@infradead.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH v2] mm: KSM: fix data types In-Reply-To: <20210716055800.GA255851@asus> Message-ID: <181bd7fd-dcb6-3dea-305c-5764603d7d45@google.com> References: <20210716055800.GA255851@asus> MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, 16 Jul 2021, Zhansaya Bagdauletkyzy wrote: > Change data types of ksm_run and ksm_stable_node_chains_prune_millisecs > as there were a few discrepancies between the types and actual values > that were stored: > 1) ksm_run is declared as unsigned long but in run_store(), it is > converted to unsigned int. Change its type to unsigned int. NAK to that part. Compiling with CONFIG_MEMORY_HOTREMOVE=y would show why. Search for where ksm_run is used: in one place there's wait_on_bit(&ksm_run, ilog2(KSM_RUN_OFFLINE), TASK_UNINTERRUPTIBLE); and wait_on_bit() operates on unsigned long *word. Before that wait while offlining, yes, ksm_run used to be an unsigned int. But there's nothing to be fixed by changing it to unsigned int now. Save four bytes? Better look elsewhere if you want to save four bytes. > 2) ksm_stable_node_chains_prune_millisecs is declared as int, but in > stable__node_chains_prune_millisecs_store(), it can store values up to > UINT_MAX. Change its type to unsigned int. Ack to that part. > > Signed-off-by: Zhansaya Bagdauletkyzy > --- > v1 -> v2: > - merge two patches into one Sorry, that didn't work out so well. Hugh > > mm/ksm.c | 12 ++++++------ > 1 file changed, 6 insertions(+), 6 deletions(-) > > diff --git a/mm/ksm.c b/mm/ksm.c > index 3fa9bc8a67cf..2e4bd7662e52 100644 > --- a/mm/ksm.c > +++ b/mm/ksm.c > @@ -259,7 +259,7 @@ static unsigned long ksm_stable_node_chains; > static unsigned long ksm_stable_node_dups; > > /* Delay in pruning stale stable_node_dups in the stable_node_chains */ > -static int ksm_stable_node_chains_prune_millisecs = 2000; > +static unsigned int ksm_stable_node_chains_prune_millisecs = 2000; > > /* Maximum number of page slots sharing a stable node */ > static int ksm_max_page_sharing = 256; > @@ -289,7 +289,7 @@ static int ksm_nr_node_ids = 1; > #define KSM_RUN_MERGE 1 > #define KSM_RUN_UNMERGE 2 > #define KSM_RUN_OFFLINE 4 > -static unsigned long ksm_run = KSM_RUN_STOP; > +static unsigned int ksm_run = KSM_RUN_STOP; > static void wait_while_offlining(void); > > static DECLARE_WAIT_QUEUE_HEAD(ksm_thread_wait); > @@ -2874,7 +2874,7 @@ KSM_ATTR(pages_to_scan); > static ssize_t run_show(struct kobject *kobj, struct kobj_attribute *attr, > char *buf) > { > - return sysfs_emit(buf, "%lu\n", ksm_run); > + return sysfs_emit(buf, "%u\n", ksm_run); > } > > static ssize_t run_store(struct kobject *kobj, struct kobj_attribute *attr, > @@ -3105,11 +3105,11 @@ stable_node_chains_prune_millisecs_store(struct kobject *kobj, > struct kobj_attribute *attr, > const char *buf, size_t count) > { > - unsigned long msecs; > + unsigned int msecs; > int err; > > - err = kstrtoul(buf, 10, &msecs); > - if (err || msecs > UINT_MAX) > + err = kstrtouint(buf, 10, &msecs); > + if (err) > return -EINVAL; > > ksm_stable_node_chains_prune_millisecs = msecs; > -- > 2.25.1