From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752211AbdBGCsk (ORCPT ); Mon, 6 Feb 2017 21:48:40 -0500 Received: from szxga01-in.huawei.com ([58.251.152.64]:52000 "EHLO szxga01-in.huawei.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751164AbdBGCsj (ORCPT ); Mon, 6 Feb 2017 21:48:39 -0500 Subject: Re: memfill To: Matthew Wilcox , Minchan Kim References: <1486307804-27903-1-git-send-email-minchan@kernel.org> <20170206144902.GH2267@bombadil.infradead.org> CC: Andrew Morton , , , , , , , , , , From: zhouxianrong Message-ID: <069b76a3-fe60-5cb1-46dd-fac977d7daf9@huawei.com> Date: Tue, 7 Feb 2017 10:47:51 +0800 User-Agent: Mozilla/5.0 (Windows NT 6.1; rv:45.0) Gecko/20100101 Thunderbird/45.0 MIME-Version: 1.0 In-Reply-To: <20170206144902.GH2267@bombadil.infradead.org> Content-Type: text/plain; charset="windows-1252"; format=flowed Content-Transfer-Encoding: 7bit X-Originating-IP: [10.142.145.228] X-CFilter-Loop: Reflected X-Mirapoint-Virus-RAPID-Raw: score=unknown(0), refid=str=0001.0A020202.58993578.014D,ss=1,re=0.000,recu=0.000,reip=0.000,cl=1,cld=1,fgs=0, ip=0.0.0.0, so=2013-06-18 04:22:30, dmn=2013-03-21 17:37:32 X-Mirapoint-Loop-Id: 505e58848bd497db73625aa1ece18cbc Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 2017/2/6 22:49, 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). > good idea, i hope kernel could support family functions like memfill/memset_long in lib. but this is beyond zram scope. > > . >