* [PATCH] shm to sysfs rebuild.
@ 2003-08-10 13:24 Frederick, Fabian
2003-08-10 17:23 ` Patrick Mochel
0 siblings, 1 reply; 4+ messages in thread
From: Frederick, Fabian @ 2003-08-10 13:24 UTC (permalink / raw)
To: 'mochel@osdl.org'; +Cc: 'linux-kernel@vger.kernel.org'
Patrick,
Here's shm to sysfs rebuild following your advices :
Summary :
-Removing kobj_map
-Adding object memsetting rather than field/field NULL
-Declaring attributes global
-Adding pointer compare rather than string compare
-Removing unnecessary pressure on the stack
-Using kobj_type
-shm destruction moved to kobject release function
-id seek was trivial.Attrshow rewritten.
-Tested against recursive fgreps-kde-personal benchmark
program
-Removed might_sleep warning (shm_unlock was global lock to
kobject_registration (fs node lock)
-Checking release code in front of all shm_destroy calls.
Patch: http://fabian.unixtech.be/kernel/shmkobject090803.diff
It's against 2.6.0test2.If it's ok to you, could you apply ?
Regards,
Fabian
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] shm to sysfs rebuild.
2003-08-10 13:24 Frederick, Fabian
@ 2003-08-10 17:23 ` Patrick Mochel
0 siblings, 0 replies; 4+ messages in thread
From: Patrick Mochel @ 2003-08-10 17:23 UTC (permalink / raw)
To: Frederick, Fabian; +Cc: 'linux-kernel@vger.kernel.org'
> Patch: http://fabian.unixtech.be/kernel/shmkobject090803.diff
>
> It's against 2.6.0test2.If it's ok to you, could you apply ?
Could you please always inline your patches in your email? They stand a
much better chance of getting applied that way.
Thanks,
-pat
^ permalink raw reply [flat|nested] 4+ messages in thread
* RE: [PATCH] shm to sysfs rebuild.
@ 2003-08-14 13:03 Frederick, Fabian
2003-08-15 0:22 ` Greg KH
0 siblings, 1 reply; 4+ messages in thread
From: Frederick, Fabian @ 2003-08-14 13:03 UTC (permalink / raw)
To: 'Patrick Mochel'; +Cc: 'linux-kernel@vger.kernel.org'
[-- Attachment #1: Type: text/plain, Size: 654 bytes --]
Patrick,
Here's the patch attached (patches are troublesome when inlined from
here).
btw all your advices were applied.
Regards,
Fabian
-----Message d'origine-----
De : Patrick Mochel [mailto:mochel@osdl.org]
Envoyé : dimanche 10 août 2003 19:24
À : Frederick, Fabian
Cc : 'linux-kernel@vger.kernel.org'
Objet : Re: [PATCH] shm to sysfs rebuild.
> Patch: http://fabian.unixtech.be/kernel/shmkobject090803.diff
>
> It's against 2.6.0test2.If it's ok to you, could you apply ?
Could you please always inline your patches in your email? They stand a
much better chance of getting applied that way.
Thanks,
-pat
[-- Attachment #2: shmkobject090803.diff --]
[-- Type: application/octet-stream, Size: 5857 bytes --]
diff -Naur orig/ipc/shm.c edited/ipc/shm.c
--- orig/ipc/shm.c 2003-07-27 17:02:04.000000000 +0000
+++ edited/ipc/shm.c 2003-08-09 22:40:59.000000000 +0000
@@ -13,6 +13,7 @@
* Shared /dev/zero support, Kanoj Sarcar <kanoj@sgi.com>
* Move the mm functionality over to mm/shmem.c, Christoph Rohland <cr@sap.com>
*
+ * sysfs support (c) 2003 Fabian Frederick <ffrederick@users.sourceforge.net>
*/
#include <linux/config.h>
@@ -27,6 +28,7 @@
#include <linux/shmem_fs.h>
#include <linux/security.h>
#include <asm/uaccess.h>
+#include <linux/kobject.h>
#include "util.h"
@@ -56,14 +58,6 @@
static int shm_tot; /* total number of shared memory pages */
-void __init shm_init (void)
-{
- ipc_init_ids(&shm_ids, 1);
-#ifdef CONFIG_PROC_FS
- create_proc_read_entry("sysvipc/shm", 0, 0, sysvipc_shm_read_proc, NULL);
-#endif
-}
-
static inline int shm_checkid(struct shmid_kernel *s, int id)
{
if (ipc_checkid(&shm_ids,&s->shm_perm,id))
@@ -81,8 +75,6 @@
return ipc_addid(&shm_ids, &shp->shm_perm, shm_ctlmni+1);
}
-
-
static inline void shm_inc (int id) {
struct shmid_kernel *shp;
@@ -93,6 +85,115 @@
shp->shm_nattch++;
shm_unlock(shp);
}
+/* sysfs exports*/
+
+#define SHM_ATTR(_name) \
+static struct attribute shm_attr_##_name={ \
+ .name=__stringify(_name), \
+ .mode=0444, \
+}; \
+
+#define ATTR_TYPE(_name) \
+&shm_attr_##_name == attr
+
+SHM_ATTR(key);
+SHM_ATTR(owner);
+SHM_ATTR(bytes);
+SHM_ATTR(perms);
+SHM_ATTR(nattach);
+SHM_ATTR(cpid);
+SHM_ATTR(lpid);
+SHM_ATTR(gid);
+SHM_ATTR(cuid);
+SHM_ATTR(cgid);
+SHM_ATTR(atime);
+SHM_ATTR(dtime);
+SHM_ATTR(ctime);
+
+static struct attribute *shm_default_attrs[] = {
+ &shm_attr_key,
+ &shm_attr_owner,
+ &shm_attr_bytes,
+ &shm_attr_perms,
+ &shm_attr_nattach,
+ &shm_attr_cpid,
+ &shm_attr_lpid,
+ &shm_attr_gid,
+ &shm_attr_cuid,
+ &shm_attr_cgid,
+ &shm_attr_atime,
+ &shm_attr_dtime,
+ &shm_attr_ctime,
+ NULL,
+};
+
+static ssize_t shm_attr_show(struct kobject *kobj, struct attribute *attr, char *buf)
+{
+ unsigned int id=simple_strtoul(kobj->name,NULL,10)%SEQ_MULTIPLIER;
+ long value;
+ struct shmid_kernel *shp;
+ down (&shm_ids.sem);
+ shp=shm_lock(id);
+ if(ATTR_TYPE(key))
+ value=shp->shm_perm.key;
+ else if(ATTR_TYPE(owner))
+ value=-1;
+ else if(ATTR_TYPE(bytes))
+ value=(int)shp->shm_segsz;
+ else if(ATTR_TYPE(perms))
+ value=shp->shm_perm.uid;
+ else if(ATTR_TYPE(nattach))
+ value=is_file_hugepages \
+ (shp->shm_file) ? (file_count(shp->shm_file)-1):\
+ shp->shm_nattch;
+ else if(ATTR_TYPE(cpid))
+ value=shp->shm_cprid;
+ else if(ATTR_TYPE(lpid))
+ value=shp->shm_lprid;
+ else if(ATTR_TYPE(gid))
+ value=shp->shm_perm.gid;
+ else if(ATTR_TYPE(cuid))
+ value=shp->shm_perm.cuid;
+ else if(ATTR_TYPE(cgid))
+ value=shp->shm_perm.cgid;
+ else if(ATTR_TYPE(atime))
+ value=(long)shp->shm_atim;
+ else if(ATTR_TYPE(dtime))
+ value=(long)shp->shm_dtim;
+ else if(ATTR_TYPE(ctime))
+ value=(long) shp->shm_ctim;
+ else value=-1;
+ snprintf(buf, PAGE_SIZE, "%ld\n", value);
+ shm_unlock(shp);
+ up (&shm_ids.sem);
+ return strlen(buf);
+}
+
+void shm_release (struct kobject *kobj)
+{
+ struct shmid_kernel *shp;
+ int id;
+ id=(int)simple_strtoul(kobj->name, NULL, 10);
+ shp = shm_lock(id);
+ shm_tot -= (shp->shm_segsz + PAGE_SIZE - 1) >> PAGE_SHIFT;
+ shm_rmid (id);
+ shm_unlock(shp);
+ if (!is_file_hugepages(shp->shm_file))
+ shmem_lock(shp->shm_file, 0);
+ fput (shp->shm_file);
+ security_shm_free(shp);
+ ipc_rcu_free(shp, sizeof(struct shmid_kernel));
+}
+
+static struct sysfs_ops shm_sysfs_ops ={
+ .show = shm_attr_show,
+};
+
+static struct kobj_type shm_ktype ={
+ .sysfs_ops = &shm_sysfs_ops,
+ .release = &shm_release,
+ .default_attrs = shm_default_attrs,
+};
/* This is called by fork, once for every shm attach. */
static void shm_open (struct vm_area_struct *shmd)
@@ -110,14 +211,8 @@
*/
static void shm_destroy (struct shmid_kernel *shp)
{
- shm_tot -= (shp->shm_segsz + PAGE_SIZE - 1) >> PAGE_SHIFT;
- shm_rmid (shp->id);
shm_unlock(shp);
- if (!is_file_hugepages(shp->shm_file))
- shmem_lock(shp->shm_file, 0);
- fput (shp->shm_file);
- security_shm_free(shp);
- ipc_rcu_free(shp, sizeof(struct shmid_kernel));
+ kobject_unregister(&shm_ids.entries[shp->id%SEQ_MULTIPLIER].kobj);
}
/*
@@ -165,6 +260,21 @@
.nopage = shmem_nopage,
};
+void __init shm_init (void)
+{
+ ipc_init_ids(&shm_ids, 1);
+#ifdef CONFIG_PROC_FS
+ create_proc_read_entry("sysvipc/shm", 0, 0, sysvipc_shm_read_proc, NULL);
+#endif
+ memset(&shm_ids.kobj, 0, sizeof(struct kobject));
+ strcpy(shm_ids.kobj.name, "shm");
+ kobject_register(&shm_ids.kobj);
+
+}
+
+
+ /* Call with shm_ids.sem locked
+ */
static int newseg (key_t key, int shmflg, size_t size)
{
int error;
@@ -223,7 +333,14 @@
else
file->f_op = &shm_file_operations;
shm_tot += numpages;
+ sprintf(shm_ids.entries[id].kobj.name, "%ld", \
+ (long)shm_buildid(id,shp->shm_perm.seq));
+ shm_ids.entries[id].kobj.parent=kobject_get(&shm_ids.kobj);
+ shm_ids.entries[id].kobj.kset=NULL;
+ shm_ids.entries[id].kobj.ktype=&shm_ktype;
shm_unlock(shp);
+ if(kobject_register(&(shm_ids.entries[id].kobj)))
+ return -EINVAL;
return shp->id;
no_id:
diff -Naur orig/ipc/util.h edited/ipc/util.h
--- orig/ipc/util.h 2003-07-27 17:03:11.000000000 +0000
+++ edited/ipc/util.h 2003-07-29 06:51:51.000000000 +0000
@@ -19,9 +19,11 @@
unsigned short seq_max;
struct semaphore sem;
struct ipc_id* entries;
+ struct kobject kobj; /* sysfs/ipc/shm {,sem,msg...} */
};
struct ipc_id {
+ struct kobject kobj; /* sysfs/ipc/xxx/yyy */
struct kern_ipc_perm* p;
};
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] shm to sysfs rebuild.
2003-08-14 13:03 [PATCH] shm to sysfs rebuild Frederick, Fabian
@ 2003-08-15 0:22 ` Greg KH
0 siblings, 0 replies; 4+ messages in thread
From: Greg KH @ 2003-08-15 0:22 UTC (permalink / raw)
To: Frederick, Fabian
Cc: 'Patrick Mochel', 'linux-kernel@vger.kernel.org'
On Thu, Aug 14, 2003 at 03:03:43PM +0200, Frederick, Fabian wrote:
> Patrick,
>
> Here's the patch attached (patches are troublesome when inlined from
> here).
> btw all your advices were applied.
Don't you really want to clean up the shm information when the device is
closed (or however shm's are destroyed), and then later, when the
kobject is released, free up the memory assigned to it?
The patch really wasn't inlined, otherwise I would point this out in the
patch :)
thanks,
greg k-h
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2003-08-15 0:24 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2003-08-14 13:03 [PATCH] shm to sysfs rebuild Frederick, Fabian
2003-08-15 0:22 ` Greg KH
-- strict thread matches above, loose matches on Subject: below --
2003-08-10 13:24 Frederick, Fabian
2003-08-10 17:23 ` Patrick Mochel
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox