From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751921AbdBGFAH (ORCPT ); Tue, 7 Feb 2017 00:00:07 -0500 Received: from LGEAMRELO12.lge.com ([156.147.23.52]:52873 "EHLO lgeamrelo12.lge.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751654AbdBGFAF (ORCPT ); Tue, 7 Feb 2017 00:00:05 -0500 X-Original-SENDERIP: 156.147.1.121 X-Original-MAILFROM: minchan@kernel.org X-Original-SENDERIP: 165.244.249.25 X-Original-MAILFROM: minchan@kernel.org X-Original-SENDERIP: 10.177.223.161 X-Original-MAILFROM: minchan@kernel.org Date: Tue, 7 Feb 2017 13:59:48 +0900 From: Minchan Kim To: Matthew Wilcox CC: Andrew Morton , , , , , , , , , , , Subject: Re: memfill Message-ID: <20170207045948.GB2215@bbox> References: <1486307804-27903-1-git-send-email-minchan@kernel.org> <20170206144902.GH2267@bombadil.infradead.org> MIME-Version: 1.0 In-Reply-To: <20170206144902.GH2267@bombadil.infradead.org> User-Agent: Mutt/1.5.24 (2015-08-30) X-MIMETrack: Itemize by SMTP Server on LGEKRMHUB01/LGE/LG Group(Release 8.5.3FP6|November 21, 2013) at 2017/02/07 13:59:48, Serialize by Router on LGEKRMHUB01/LGE/LG Group(Release 8.5.3FP6|November 21, 2013) at 2017/02/07 13:59:48, Serialize complete at 2017/02/07 13:59:48 Content-Type: text/plain; charset="us-ascii" Content-Disposition: inline Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi Matthew, On Mon, Feb 06, 2017 at 06:49:02AM -0800, Matthew Wilcox wrote: > > [adding linux-arch to see if anyone there wants to do an optimised > version of memfill for their CPU] > > On Mon, Feb 06, 2017 at 12:16:44AM +0900, Minchan Kim wrote: > > +static inline void zram_fill_page(char *ptr, unsigned long len, > > + unsigned long value) > > +{ > > + int i; > > + unsigned long *page = (unsigned long *)ptr; > > + > > + WARN_ON_ONCE(!IS_ALIGNED(len, sizeof(unsigned long))); > > + > > + if (likely(value == 0)) { > > + memset(ptr, 0, len); > > + } else { > > + for (i = 0; i < len / sizeof(*page); i++) > > + page[i] = value; > > + } > > +} > > I would suggest: > > #ifndef __HAVE_ARCH_MEMFILL > /** > * memfill - Fill a region of memory with the given value > * @s: Pointer to the start of the region. > * @v: The word to fill the region with. > * @n: The size of the region. > * > * Differs from memset() in that it fills with an unsigned long instead of > * a byte. The pointer and the size must be aligned to unsigned long. > */ > void memfill(unsigned long *s, unsigned long v, size_t n) > { > WARN_ON_ONCE(!IS_ALIGNED(n, sizeof(v))); > > if (likely(v == 0)) { > memset(s, 0, n); > } else { > while (n) { > *s++ = v; > n -= sizeof(v); > } > } > } > EXPORT_SYMBOL(memfill); > #endif > > (I would also suggest this move to lib/string.c and architectures be > given the opportunity to provide an optimised version of memfill). Thanks for suggestion, Matthew! However, I want to mention zram's performance wouldn't be sensitive for that function because non-zero memfill would be rare.