Linux 15.070 Themen, 107.540 Beiträge

tmp..filesystem..sticky bit

ghartl1 / 10 Antworten / Baumansicht Nickles

hallo,

hab wieder mal eine frage ...nona :-)

das sticky bit wird ja hauptsächlich im tmp-verzeichnis verwendet, um allgemeine daten nur vom besitzer verändern lassen zu können (vereinfacht ausgedrückt)
jetzt hab ich aber gelesen, dass das stickybit programme nicht aus dem arbeitsspeicher löscht, wenn sie nicht mehr gebraucht werden....wie kann man das zu seinem vorteil nutzen..oder wo macht man sowas?

2 frage: es gibt ein virtuelles filesystem tmpfs...das "angeblich" im tmp verzeichnis zum tragen kommt.
ist das auch so, auch wenn ich ext3 alles formatiert habe?
was wäre drer sinn von tmpfs??
wird tmpfs automatisch angelegt in /tmp??
programme legen ja auch einen teil ihres platzes auf tmp ab, falls ram zu klein ist
wieso brauch ich da ein "extra"dateisystem...

bei proc kapier ichs ja...schnittstelle zu kernelmeldungen..
swapfs..auslagerungsdatei...okay

heisst das jetzt ich hab unter linux tmpfs und swapfs zum auslagern??

gruss günter

bei Antwort benachrichtigen
KarstenW ghartl1 „tmp..filesystem..sticky bit“
Optionen

Das mit diesem sticky Bit stimmt. Das steht auch in der Wikipedia:

http://de.wikipedia.org/wiki/Sticky_Bit

Ich glaube aber nicht das es bei ausführbaren Dateien unter Linux eingesetzt wird. Der Linux Betriebsystemkern verwendet ohnehin einen sehr großen Teil des RAM als Puffer um Daten im RAM zu halten und nicht nochmal neu von Festplatte lesen zu müssen.

free
total used free shared buffers cached
Mem: 255952 246104 9848 0 1484 44340
-/+ buffers/cache: 200280 55672
Swap: 514040 167788 346252

Deshalb wundern sich Linuxneulinge immer warum der RAM komplett ausgenutzt wird, wohingegen bei Windows nur ein Teil des RAM verwendet wird (die Speicherverwaltung von Windows ist eh' Schrott) ;-).


Der Ausgabe von df zu Folge hat tmpfs nichts mit der swap Partition zu tun:

df

Dateisystem 1K-Blöcke Benutzt Verfügbar Ben% Eingehängt auf
/dev/hda1 8262036 1222996 6619344 16% /
tmpfs 127976 0 127976 0% /lib/init/rw
udev 10240 48 10192 1% /dev
tmpfs 127976 8 127968 1% /dev/shm
/dev/hda8 17299004 10876948 5543304 67% /home
/dev/hda7 8262036 1878160 5964180 24% /usr
/dev/hda6 4134900 1442276 2482576 37% /var

Ich wüßte auch nicht das die swap Partition irgendein Dateisystem hat. Der Betriebsystemkern lagert Speicherseiten nach swap aus, wenn der RAM nicht mehr reicht. Die Programme lagern überhaupt keinen Speicher nach swap aus. Die Speicherverwaltung ist Aufgabe des Betriebsystemkerns.
Die Daten werden in der swap Partition sequentiel (nacheinander ) gelesen und geschrieben. Daher glaube ich nicht das die swap Partition ein Dateisystem hat.
Deshalb ist auch eine Swap-Partition schneller als eine Swapdatei wie bei Windows, weil die Auslagerungs-Daten nicht fragmentiert werden.
tmpfs wird wahrscheinlich ein Dateisystem im RAM sein (wie /proc ./proc gibt es auch nicht auf der Festplatte).
Der Linuxkernel hat viel von Unix übernommen und bei Unix gibt es sechs Systemaufrufe , auf die die anderen Systemaufrufe (sind im POSIX Standard festgelegt) aufbauen:
-read, write
-open, close
-fork , execl

Man sagt auch das bei Unix alles eine Datei ist. Der Programmierer hat immer nur Dateioperationen zu programmieren ,die sich relativ einfach programmieren lassen.
Ich nehme mal an das tmpfs ein Dateisystem im RAM ist.
Eine Art RAM Disk eventuell, keine Ahnung .

Debian GNU/Linux https://www.debian.org/index.de.html
bei Antwort benachrichtigen
KarstenW Nachtrag zu: „Das mit diesem sticky Bit stimmt. Das steht auch in der Wikipedia:...“
Optionen

Ich kann dir nur empfehlen mal ein Buch spezielle zu Linux durchzulesen. Dafür mußt du auch kein Kernelentwickler sein:

Linux-Kernel Handbuch. Leitfaden zu Design und Implementierung von Kernel 2.6 (Open Source Library) (Gebundene Ausgabe)
von Robert Love

http://www.amazon.de/Linux-Kernel-Handbuch-Leitfaden-Implementierung-Library/dp/3827322049/ref=pd_bbs_sr_2/302-5361123-0438441?ie=UTF8&s=books&qid=1194981476&sr=8-2

Die Speicherverwaltung ist Aufgabe des Linuxkernels.

Debian GNU/Linux https://www.debian.org/index.de.html
bei Antwort benachrichtigen
KarstenW ghartl1 „tmp..filesystem..sticky bit“
Optionen

Man kann /tmp auf eine eigene Partition auslagern. Das wird im Serverbereich empfohlen. /tmp muß für alle Anwender schreibbar sein und deshalb gibt es im Serverbereich das Risiko, das durch sehr große oder sehr viele temporäre Daten die Festplatte geflutet wird . Wenn der Betriebsystem nicht mehr auf die Festplatte schreiben kann, dann hängt sich das ganze System auf und der Server stürtzt ab.
Wenn du /tmp im Serverbereich auf eine eigene Partition auslagerst, dann kannst du auch ein einfaches Dateisystem wie ext2 für /tmp nutzen.
Also das Dateisystem tmpfs hat nichts mit dem /tmp-Verzeichnis zu tun. Ich denke das tmpfs eine Art RAM Disk ist für temporäre Daten die im Speicher gehalten werden. Weiß ich aber nicht so genau.

Debian GNU/Linux https://www.debian.org/index.de.html
bei Antwort benachrichtigen
ghartl1 KarstenW „Man kann /tmp auf eine eigene Partition auslagern. Das wird im Serverbereich...“
Optionen

hmmm..das mit swap is mir e klar..nur das tmpfs nicht.

ich zitiere (ist aus einem buch)
das tmpfs dient zur aufnahme temporärer dateien. es imitiert eine virtuelle festplatte im hauptspeicher und ist das dateisystem für das verzeichnis /tmp.
...sind die daten zu gross für den adressraum des prozesses, dann wird ein teil der daten als temporäre datei ausgelagert und für den späteren gebrauch auf die festplatte geschrieben.(wie jetzt..kommt das in tmp oder in swap rein?)
beim erneuten start des prozesses wird dieser seine informationen dort wiederfinden.

das war der originalgetreue auszug...über virtuelle dateisysteme...ganz blick ich noch nicht durch

gruss günter

bei Antwort benachrichtigen
KarstenW ghartl1 „hmmm..das mit swap is mir e klar..nur das tmpfs nicht. ich zitiere ist aus einem...“
Optionen

Ist das ein Buch über Unix oder den Linuxbetriebsystemkern ?
Das ist eine Kopie vom Dialog der Konfiguration eines eigenen Linuxkernels:

────────────────────────── Virtual memory file system support (former shm fs) ───────────────────────────┐
│ CONFIG_TMPFS: │
│ │
│ Tmpfs is a file system which keeps all files in virtual memory. │
│ │
│ Everything in tmpfs is temporary in the sense that no files will be │
│ created on your hard drive. The files live in memory and swap │
│ space. If you unmount a tmpfs instance, everything stored therein is │
│ lost. │
│ │
│ See file:Documentation/filesystems/tmpfs.txt for details.

Ich bin leider kein Systemprogrammierer. Das Verzeichnis /tmp existiert auch auf der Festplatte und kann auf eine eigene Partition ausgelagert werden. Das wird im Serverbereich wegen der Gefahr des Vollaufens der Festplatte empfohlen. In /tmp werden von den Programmen der Benutzer temporäre Daten gespeichert. Wahrscheinlich ist dann das Tmpfs Dateisystem für spezielle temporäre Daten vorgesehen.
Auf jeden Fall hat tmpfs nichts mit dem Verzeichnis /tmp auf der Festplatte zu tun. Man kann /tmp auf eine eigene Partition legen und beispielsweise mit dem Dateisystem ext2 formatieren.
Die Auslagerungspartition swap hat meines Wissens nach auch kein Dateisystem. Die Daten auf swap werden sequentiel gelesen und geschrieben.

Linux ist auch kein Unix. Es wurden nur ein paar Konzepte übernommen. Der POSIX Standard ist zu einem großen Teil von der Linux Standard Base übernommen worden , ist aber auch weiterentwickelt worden. Also wenn das ein Buch über Unix ist,dann sind ein paar Sachen nicht ganz identisch mit Linux.
Damit Linux als Unix von The Open Group zertifiziert werden könnte, müßte sich Linux 100 %ig an die Spezifikation der Unix Spezifikation von The Open Group halten.

Debian GNU/Linux https://www.debian.org/index.de.html
bei Antwort benachrichtigen
KarstenW ghartl1 „hmmm..das mit swap is mir e klar..nur das tmpfs nicht. ich zitiere ist aus einem...“
Optionen

/usr/src/linux-source-2.6.18/Documentation/filesystems# cat tmpfs.txt


Tmpfs is a file system which keeps all files in virtual memory.


Everything in tmpfs is temporary in the sense that no files will be
created on your hard drive. If you unmount a tmpfs instance,
everything stored therein is lost.

tmpfs puts everything into the kernel internal caches and grows and
shrinks to accommodate the files it contains and is able to swap
unneeded pages out to swap space. It has maximum size limits which can
be adjusted on the fly via 'mount -o remount ...'

If you compare it to ramfs (which was the template to create tmpfs)
you gain swapping and limit checking. Another similar thing is the RAM
disk (/dev/ram*), which simulates a fixed size hard disk in physical
RAM, where you have to create an ordinary filesystem on top. Ramdisks
cannot swap and you do not have the possibility to resize them.

Since tmpfs lives completely in the page cache and on swap, all tmpfs
pages currently in memory will show up as cached. It will not show up
as shared or something like that. Further on you can check the actual
RAM+swap use of a tmpfs instance with df(1) and du(1).


tmpfs has the following uses:

1) There is always a kernel internal mount which you will not see at
all. This is used for shared anonymous mappings and SYSV shared
memory.

This mount does not depend on CONFIG_TMPFS. If CONFIG_TMPFS is not
set, the user visible part of tmpfs is not build. But the internal
mechanisms are always present.

2) glibc 2.2 and above expects tmpfs to be mounted at /dev/shm for
POSIX shared memory (shm_open, shm_unlink). Adding the following
line to /etc/fstab should take care of this:

tmpfs /dev/shm tmpfs defaults 0 0

Remember to create the directory that you intend to mount tmpfs on
if necessary (/dev/shm is automagically created if you use devfs).

This mount is _not_ needed for SYSV shared memory. The internal
mount is used for that. (In the 2.3 kernel versions it was
necessary to mount the predecessor of tmpfs (shm fs) to use SYSV
shared memory)

3) Some people (including me) find it very convenient to mount it
e.g. on /tmp and /var/tmp and have a big swap partition. And now
loop mounts of tmpfs files do work, so mkinitrd shipped by most
distributions should succeed with a tmpfs /tmp.

4) And probably a lot more I do not know about :-)


tmpfs has three mount options for sizing:

size: The limit of allocated bytes for this tmpfs instance. The
default is half of your physical RAM without swap. If you
oversize your tmpfs instances the machine will deadlock
since the OOM handler will not be able to free that memory.
nr_blocks: The same as size, but in blocks of PAGE_CACHE_SIZE.
nr_inodes: The maximum number of inodes for this instance. The default
is half of the number of your physical RAM pages, or (on a
a machine with highmem) the number of lowmem RAM pages,
whichever is the lower.

These parameters accept a suffix k, m or g for kilo, mega and giga and
can be changed on remount. The size parameter also accepts a suffix %
to limit this tmpfs instance to that percentage of your physical RAM:
the default, when neither size nor nr_blocks is specified, is size=50%

If nr_blocks=0 (or size=0), blocks will not be limited in that instance;
if nr_inodes=0, inodes will not be limited. It is generally unwise to
mount with such options, since it allows any user with write access to
use up all the memory on the machine; but enhances the scalability of
that instance in a system with many cpus making intensive use of it.


tmpfs has a mount option to set the NUMA memory allocation policy for
all files in that instance (if CONFIG_NUMA is enabled) - which can be
adjusted on the fly via 'mount -o remount ...'

mpol=default prefers to allocate memory from the local node
mpol=prefer:Node prefers to allocate memory from the given Node
mpol=bind:NodeList allocates memory only from nodes in NodeList
mpol=interleave prefers to allocate from each node in turn
mpol=interleave:NodeList allocates from each node of NodeList in turn

NodeList format is a comma-separated list of decimal numbers and ranges,
a range being two hyphen-separated decimal numbers, the smallest and
largest node numbers in the range. For example, mpol=bind:0-3,5,7,9-15

Note that trying to mount a tmpfs with an mpol option will fail if the
running kernel does not support NUMA; and will fail if its nodelist
specifies a node >= MAX_NUMNODES. If your system relies on that tmpfs
being mounted, but from time to time runs a kernel built without NUMA
capability (perhaps a safe recovery kernel), or configured to support
fewer nodes, then it is advisable to omit the mpol option from automatic
mount options. It can be added later, when the tmpfs is already mounted
on MountPoint, by 'mount -o remount,mpol=Policy:NodeList MountPoint'.


To specify the initial root directory you can use the following mount
options:

mode: The permissions as an octal number
uid: The user id
gid: The group id

These options do not have any effect on remount. You can change these
parameters with chmod(1), chown(1) and chgrp(1) on a mounted filesystem.


So 'mount -t tmpfs -o size=10G,nr_inodes=10k,mode=700 tmpfs /mytmpfs'
will give you tmpfs instance on /mytmpfs which can allocate 10GB
RAM/SWAP in 10240 inodes and it is only accessible by root.


Author:
Christoph Rohland

Debian GNU/Linux https://www.debian.org/index.de.html
bei Antwort benachrichtigen
ghartl1 KarstenW „/usr/src/linux-source-2.6.18/Documentation/filesystems cat tmpfs.txt Tmpfs is a...“
Optionen

hmm..dr auszug war aus einem linux buch

muss mir später mal genauer deine message anschaun..danke einstweilen

gruss günter

bei Antwort benachrichtigen
KarstenW ghartl1 „hmm..dr auszug war aus einem linux buch muss mir später mal genauer deine...“
Optionen

Wenn dieses Buch aus dem Englischen übersetzt worden ist, dann kann es immer wieder mal passieren das Fehler in die deutsche Übersetzung reinkommen. Die Übersetzer haben teilweise gar keine Ahnung was sie da übersetzen.
Wenn mein Englisch nicht so schlecht wäre, würde ich überhaupt keine deutschen Übersetzungen lesen, immer nur das Original !

Konfiguriere lieber mal einen eigenen Linuxkernel. Vor allem im Dokumentationsverzeichnis sind ein paar Sachen recht gut erklärt (wie du aus meinem Posting eventuell erkennen kannst).
Ist aber leider alles in English.


Debian GNU/Linux https://www.debian.org/index.de.html
bei Antwort benachrichtigen
ghartl1 KarstenW „Wenn dieses Buch aus dem Englischen übersetzt worden ist, dann kann es immer...“
Optionen

englisch wär net das problem..nur linux :-)
danke für die ausführungen

gruss günter

bei Antwort benachrichtigen
ghartl1 Nachtrag zu: „englisch wär net das problem..nur linux :- danke für die ausführungen gruss günter“
Optionen

sodah..hab mir das jetzt in ruhe angesehen....damit kann ich leben :-)

danke karstenw für die ausführungen...

gruss günter

bei Antwort benachrichtigen